1313
1414
1515@with_langtrace_root_span ("Litellm Example OpenAI" )
16- def openAI ():
16+ def openAI (streaming = False ):
1717 response = completion (
1818 model = "gpt-3.5-turbo" ,
1919 messages = [
2020 {"content" : "respond only in Yoda speak." , "role" : "system" },
2121 {"content" : "Hello, how are you?" , "role" : "user" },
2222 ],
23+ stream = streaming ,
24+ stream_options = {"include_usage" : True },
2325 )
24- return response
26+ if streaming :
27+ for _ in response :
28+ pass
29+ else :
30+ return response
2531
2632
2733# @with_langtrace_root_span("Litellm Example Anthropic Completion")
2834def anthropic (streaming = False ):
2935 try :
3036
3137 response = completion (
32- model = "claude-2" ,
38+ model = "claude-2.1 " ,
3339 messages = [
3440 {"content" : "respond only in Yoda speak." , "role" : "system" },
3541 {"content" : "what is 2 + 2?" , "role" : "user" },
@@ -53,7 +59,7 @@ def anthropic(streaming=False):
5359# @with_langtrace_root_span("Litellm Example OpenAI Async Streaming")
5460async def async_anthropic (streaming = False ):
5561 response = await acompletion (
56- model = "claude-2" ,
62+ model = "claude-2.1 " ,
5763 messages = [{"content" : "Hello, how are you?" , "role" : "user" }],
5864 stream = streaming ,
5965 stream_options = {"include_usage" : True },
@@ -68,7 +74,25 @@ async def async_anthropic(streaming=False):
6874 return response
6975
7076
77+ def cohere (streaming = False ):
78+ response = completion (
79+ model = "command-r" ,
80+ messages = [
81+ {"content" : "respond only in Yoda speak." , "role" : "system" },
82+ {"content" : "Hello, how are you?" , "role" : "user" },
83+ ],
84+ stream = streaming ,
85+ stream_options = {"include_usage" : True },
86+ )
87+ if streaming :
88+ for _ in response :
89+ pass
90+ else :
91+ return response
92+
93+
7194if __name__ == "__main__" :
7295 # openAI()
73- # anthropic(streaming=False)
74- asyncio .run (async_anthropic (streaming = True ))
96+ anthropic (streaming = False )
97+ cohere (streaming = True )
98+ # asyncio.run(async_anthropic(streaming=True))
0 commit comments