mirror of
https://github.com/tiennm99/litellm.git
synced 2026-07-15 20:20:28 +00:00
11 KiB
Vendored
11 KiB
Vendored
In [ ]:
!pip install litellmIn [1]:
from litellm import completion
import osIn [4]:
# Only set keys for the LLMs you want to use
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 [2]:
messages = [{ "content": "what's the weather in SF","role": "user"}]In [3]:
completion(model="gpt-3.5-turbo", messages=messages)Out [3]:
<OpenAIObject chat.completion id=chatcmpl-7vYWJYYUeFuhjCiOjI9JXK6gNmWk3 at 0x1067d42c0> JSON: {
"id": "chatcmpl-7vYWJYYUeFuhjCiOjI9JXK6gNmWk3",
"object": "chat.completion",
"created": 1693951747,
"model": "gpt-3.5-turbo-0613",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "I apologize, but as an AI language model, I do not have real-time data. However, you can easily find the current weather conditions in San Francisco, California by checking a trusted weather website or using a weather app on your smartphone."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 13,
"completion_tokens": 48,
"total_tokens": 61
}
}In [ ]:
completion(model="claude-2", messages=messages){'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 [ ]:
model = "replicate/llama-2-70b-chat:2c1608e18606fad2812020dc541930f2d0495ce32eee50074220b87300bc16e1"
completion(model=model, messages=messages){'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 [7]:
completion(model="command-nightly", messages=messages)Out [7]:
<ModelResponse at 0x11cb0c3b0> JSON: {
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": " The weather in San Francisco can be quite unpredictable and varies throughout the year. In general, the city",
"role": "assistant",
"logprobs": null
}
}
],
"created": 1693951797.3149078,
"model": "command-nightly",
"usage": {
"prompt_tokens": 6,
"completion_tokens": 20,
"total_tokens": 26
}
}In [ ]:
completion(model="azure/chatgpt-test", messages=messages)