mirror of
https://github.com/tiennm99/litellm.git
synced 2026-07-28 20:20:56 +00:00
11 KiB
11 KiB
In [ ]:
!pip install litellmIn [2]:
from litellm import completion
import osIn [23]:
os.environ['OPENAI_API_KEY'] = "" #@param
os.environ["ANTHROPIC_API_KEY"] = "" #@param
os.environ["AZURE_API_BASE"] = "" #@param
os.environ["AZURE_API_VERSION"] = "" #@param
os.environ["AZURE_API_KEY"] = "" #@param
os.environ["REPLICATE_API_TOKEN"] = "" #@param
os.environ["COHERE_API_KEY"] = "" #@param
os.environ["HF_TOKEN"] = "" #@paramIn [3]:
messages = [{ "content": "what's the weather in SF","role": "user"}]In [9]:
completion(model="gpt-3.5-turbo", messages=messages)Out [9]:
<OpenAIObject chat.completion id=chatcmpl-7mrklZEq2zK3Z5pSkOR3Jn54gpN5A at 0x7f76df70e930> JSON: {
"id": "chatcmpl-7mrklZEq2zK3Z5pSkOR3Jn54gpN5A",
"object": "chat.completion",
"created": 1691880727,
"model": "gpt-3.5-turbo-0613",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "I'm sorry, but as an AI language model, I don't have real-time data. However, you can check the current weather in San Francisco by using a weather website or app, or by searching \"weather in San Francisco\" on a search engine."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 13,
"completion_tokens": 52,
"total_tokens": 65
}
}In [11]:
completion(model="claude-2", messages=messages)Out [11]:
{'choices': [{'finish_reason': 'stop',
'index': 0,
'message': {'role': 'assistant',
'content': " Unfortunately I do not have enough context to provide the current weather in San Francisco. To get the most accurate weather report, it's helpful if I know details like:\n\n- Exact location (city name, zip code, etc)\n- Time frame (current conditions, forecast for a certain day/week, etc)\n\nIf you can provide some more specifics about what weather information you need for San Francisco, I'd be happy to look that up for you!"}}],
'created': 1691880836.974166,
'model': 'claude-2',
'usage': {'prompt_tokens': 18, 'completion_tokens': 95, 'total_tokens': 113}}In [13]:
model = "replicate/llama-2-70b-chat:2c1608e18606fad2812020dc541930f2d0495ce32eee50074220b87300bc16e1"
completion(model=model, messages=messages)Out [13]:
{'choices': [{'finish_reason': 'stop',
'index': 0,
'message': {'role': 'assistant',
'content': ' I\'m happy to help! However, I must point out that the question "what\'s the weather in SF" doesn\'t make sense as "SF" could refer to multiple locations (San Francisco, South Florida, San Fernando, etc.). Could you please provide more context or specify which location you\'re referring to? That way, I can give you an accurate answer.'}}],
'created': 1691880930.9003325,
'model': 'replicate/llama-2-70b-chat:2c1608e18606fad2812020dc541930f2d0495ce32eee50074220b87300bc16e1',
'usage': {'prompt_tokens': 6, 'completion_tokens': 74, 'total_tokens': 80}}In [15]:
completion(model="command-nightly", messages=messages)Out [15]:
{'choices': [{'finish_reason': 'stop',
'index': 0,
'message': {'role': 'assistant',
'content': ' The weather in San Francisco can be quite unpredictable. The city is known for its fog, which can'}}],
'created': 1691880972.5565543,
'model': 'command-nightly',
'usage': {'prompt_tokens': 6, 'completion_tokens': 20, 'total_tokens': 26}}In [24]:
completion(deployment_id="chatgpt-test", messages=messages, azure=True)Out [24]:
<OpenAIObject chat.completion id=chatcmpl-7mrtwvpx3okijXmbt9PEYdPMeE7lH at 0x7f76cfb356c0> JSON: {
"id": "chatcmpl-7mrtwvpx3okijXmbt9PEYdPMeE7lH",
"object": "chat.completion",
"created": 1691881296,
"model": "gpt-35-turbo",
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": "I'm sorry, as an AI language model, I don't have real-time data. However, you can check the weather forecast for San Francisco on websites such as AccuWeather or Weather Channel."
}
}
],
"usage": {
"completion_tokens": 40,
"prompt_tokens": 14,
"total_tokens": 54
}
}