|
13 | 13 | # Test 1: Simple string input |
14 | 14 | print("Test 1: Simple string input") |
15 | 15 | response1 = edgee.send( |
16 | | - model="gpt-4o", |
| 16 | + model="mistral/mistral-small-latest", |
17 | 17 | input="What is the capital of France?", |
18 | 18 | ) |
19 | 19 | print(f"Content: {response1.choices[0].message['content']}") |
|
23 | 23 | # Test 2: Full input object with messages |
24 | 24 | print("Test 2: Full input object with messages") |
25 | 25 | response2 = edgee.send( |
26 | | - model="gpt-4o", |
| 26 | + model="mistral/mistral-small-latest", |
27 | 27 | input={ |
28 | 28 | "messages": [ |
29 | 29 | {"role": "system", "content": "You are a helpful assistant."}, |
|
35 | 35 | print() |
36 | 36 |
|
37 | 37 | # Test 3: With tools |
38 | | -print("Test 3: With tools") |
39 | | -response3 = edgee.send( |
40 | | - model="gpt-4o", |
| 38 | +#print("Test 3: With tools") |
| 39 | +#response3 = edgee.send( |
| 40 | +# model="gpt-4o", |
| 41 | +# input={ |
| 42 | +# "messages": [{"role": "user", "content": "What is the weather in Paris?"}], |
| 43 | +# "tools": [ |
| 44 | +# { |
| 45 | +# "type": "function", |
| 46 | +# "function": { |
| 47 | +# "name": "get_weather", |
| 48 | +# "description": "Get the current weather for a location", |
| 49 | +# "parameters": { |
| 50 | +# "type": "object", |
| 51 | +# "properties": { |
| 52 | +# "location": {"type": "string", "description": "City name"}, |
| 53 | +# }, |
| 54 | +# "required": ["location"], |
| 55 | +# }, |
| 56 | +# }, |
| 57 | +# }, |
| 58 | +# ], |
| 59 | +# "tool_choice": "auto", |
| 60 | +# }, |
| 61 | +#) |
| 62 | +#print(f"Content: {response3.choices[0].message.get('content')}") |
| 63 | +#print(f"Tool calls: {response3.choices[0].message.get('tool_calls')}") |
| 64 | +#print() |
| 65 | + |
| 66 | +# Test 4: Streaming |
| 67 | +print("Test 4: Streaming") |
| 68 | +for chunk in edgee.stream( |
| 69 | + model="mistral/mistral-small-latest", |
| 70 | + input="Tell me a short story about a robot", |
| 71 | +): |
| 72 | + if chunk.choices[0].delta.content: |
| 73 | + print(chunk.choices[0].delta.content, end="", flush=True) |
| 74 | +print("\n") |
| 75 | + |
| 76 | +# Test 5: Streaming with messages |
| 77 | +print("Test 5: Streaming with system message") |
| 78 | +for chunk in edgee.stream( |
| 79 | + model="mistral/mistral-small-latest", |
41 | 80 | input={ |
42 | | - "messages": [{"role": "user", "content": "What is the weather in Paris?"}], |
43 | | - "tools": [ |
44 | | - { |
45 | | - "type": "function", |
46 | | - "function": { |
47 | | - "name": "get_weather", |
48 | | - "description": "Get the current weather for a location", |
49 | | - "parameters": { |
50 | | - "type": "object", |
51 | | - "properties": { |
52 | | - "location": {"type": "string", "description": "City name"}, |
53 | | - }, |
54 | | - "required": ["location"], |
55 | | - }, |
56 | | - }, |
57 | | - }, |
| 81 | + "messages": [ |
| 82 | + {"role": "system", "content": "You are a poetic assistant. Respond in rhyme."}, |
| 83 | + {"role": "user", "content": "What is Python?"}, |
58 | 84 | ], |
59 | | - "tool_choice": "auto", |
60 | 85 | }, |
61 | | -) |
62 | | -print(f"Content: {response3.choices[0].message.get('content')}") |
63 | | -print(f"Tool calls: {response3.choices[0].message.get('tool_calls')}") |
| 86 | +): |
| 87 | + delta = chunk.choices[0].delta |
| 88 | + if delta.role: |
| 89 | + print(f"[Role: {delta.role}]") |
| 90 | + if delta.content: |
| 91 | + print(delta.content, end="", flush=True) |
| 92 | + if chunk.choices[0].finish_reason: |
| 93 | + print(f"\n[Finished: {chunk.choices[0].finish_reason}]") |
| 94 | +print() |
0 commit comments