Skip to content

Commit 7c8cc4d

Browse files
committed
fix(python): revert all sdk changes on python for now
Signed-off-by: Samantha Coyle <sam@diagrid.io>
1 parent 8c02d85 commit 7c8cc4d

File tree

3 files changed

+27
-59
lines changed

3 files changed

+27
-59
lines changed

conversation/python/sdk/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,25 @@ For more LLM options, see the [supported Conversation components](https://docs.d
7070
name: Run multi app run template
7171
expected_stdout_lines:
7272
- '== APP - conversation-sdk == Input sent: What is dapr?'
73-
- '== APP - conversation-sdk == Output response:'
73+
- '== APP - conversation-sdk == Output response: What is dapr?'
7474
expected_stderr_lines:
7575
output_match_mode: substring
7676
match_order: none
7777
background: true
78-
sleep: 30
79-
timeout_seconds: 60
78+
sleep: 15
79+
timeout_seconds: 30
8080
-->
81-
81+
8282
```bash
8383
source conversation/.venv/bin/activate
84-
dapr run -f .
84+
dapr run -f .
8585
```
86-
86+
8787
Expected output:
88-
88+
8989
```text
9090
== APP - conversation-sdk == Input sent: What is dapr?
91-
== APP - conversation-sdk == Output response: Dapr is an open-source, cross-platform microservices framework...
91+
== APP - conversation-sdk == Output response: What is dapr?
9292
```
9393

9494
<!-- END_STEP -->
@@ -112,15 +112,15 @@ For more LLM options, see the [supported Conversation components](https://docs.d
112112
name: Run multi app run template
113113
expected_stdout_lines:
114114
- "== APP - conversation-tool-calling == Input sent: calculate square root of 15"
115-
- "== APP - conversation-tool-calling == Output response: ConversationResultAlpha2Choices(finish_reason='tool_calls'"
115+
- "== APP - conversation-tool-calling == Output response: ConversationResultAlpha2Choices(finish_reason='tool_calls', index=0, message=ConversationResultAlpha2Message(content='calculate square root of 15', tool_calls=[ConversationToolCalls(id='0', function=ConversationToolCallsOfFunction(name='calculate', arguments='expression'))]))"
116116
- "== APP - conversation-tool-calling == Input sent: get weather in San Francisco in celsius"
117-
- "== APP - conversation-tool-calling == Output response: ConversationResultAlpha2Choices(finish_reason='tool_calls'"
117+
- "== APP - conversation-tool-calling == Output response: ConversationResultAlpha2Choices(finish_reason='tool_calls', index=0, message=ConversationResultAlpha2Message(content='get weather in San Francisco in celsius', tool_calls=[ConversationToolCalls(id='0', function=ConversationToolCallsOfFunction(name='get_weather', arguments='location,unit'))]))"
118118
expected_stderr_lines:
119119
output_match_mode: substring
120120
match_order: none
121121
background: true
122-
sleep: 30
123-
timeout_seconds: 60
122+
sleep: 15
123+
timeout_seconds: 30
124124
-->
125125

126126
```bash
@@ -132,9 +132,9 @@ For more LLM options, see the [supported Conversation components](https://docs.d
132132

133133
```text
134134
== APP - conversation-tool-calling == Input sent: calculate square root of 15
135-
== APP - conversation-tool-calling == Output response: ConversationResultAlpha2Choices(finish_reason='tool_calls', index=0, message=ConversationResultAlpha2Message(content='calculate square root of 15', tool_calls=[ConversationToolCalls(id='call_...', function=ConversationToolCallsOfFunction(name='calculate', arguments='{"expression": "sqrt(15)"}'))]))
135+
== APP - conversation-tool-calling == Output response: ConversationResultAlpha2Choices(finish_reason='tool_calls', index=0, message=ConversationResultAlpha2Message(content='calculate square root of 15', tool_calls=[ConversationToolCalls(id='0', function=ConversationToolCallsOfFunction(name='calculate', arguments='expression'))]))
136136
== APP - conversation-tool-calling == Input sent: get weather in San Francisco in celsius
137-
== APP - conversation-tool-calling == Output response: ConversationResultAlpha2Choices(finish_reason='tool_calls', index=0, message=ConversationResultAlpha2Message(content='get weather in San Francisco in celsius', tool_calls=[ConversationToolCalls(id='call_...', function=ConversationToolCallsOfFunction(name='get_weather', arguments='{"location": "San Francisco", "unit": "celsius"}'))]))
137+
== APP - conversation-tool-calling == Output response: ConversationResultAlpha2Choices(finish_reason='tool_calls', index=0, message=ConversationResultAlpha2Message(content='get weather in San Francisco in celsius', tool_calls=[ConversationToolCalls(id='0', function=ConversationToolCallsOfFunction(name='get_weather', arguments='location,unit'))]))
138138
```
139139

140140
<!-- END_STEP -->

conversation/python/sdk/conversation/app.py

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,21 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
1212
# ------------------------------------------------------------
13-
import sys
1413
from dapr.clients import DaprClient
1514
from dapr.clients.grpc.conversation import ConversationInputAlpha2, ConversationMessage, ConversationMessageContent, ConversationMessageOfUser
1615

17-
try:
18-
with DaprClient() as d:
19-
text_input = "What is dapr?"
20-
provider_component = "ollama"
16+
with DaprClient() as d:
17+
text_input = "What is dapr?"
18+
provider_component = "echo"
2119

22-
inputs = [
23-
ConversationInputAlpha2(messages=[ConversationMessage(of_user=ConversationMessageOfUser(content=[ConversationMessageContent(text=text_input)]))],
24-
scrub_pii=True),
25-
]
20+
inputs = [
21+
ConversationInputAlpha2(messages=[ConversationMessage(of_user=ConversationMessageOfUser(content=[ConversationMessageContent(text=text_input)]))],
22+
scrub_pii=True),
23+
]
2624

27-
print(f'Input sent: {text_input}', flush=True)
25+
print(f'Input sent: {text_input}')
2826

29-
response = d.converse_alpha2(name=provider_component, inputs=inputs, temperature=0.7)
30-
31-
if response and hasattr(response, 'outputs') and response.outputs:
32-
for output in response.outputs:
33-
if hasattr(output, 'model') and output.model:
34-
print(f'Model: {output.model}', flush=True)
35-
36-
if hasattr(output, 'usage') and output.usage:
37-
usage = output.usage
38-
prompt_tokens = getattr(usage, 'prompt_tokens', None) or getattr(usage, 'promptTokens', None)
39-
completion_tokens = getattr(usage, 'completion_tokens', None) or getattr(usage, 'completionTokens', None)
40-
total_tokens = getattr(usage, 'total_tokens', None) or getattr(usage, 'totalTokens', None)
41-
print(f'Usage: prompt_tokens={prompt_tokens} completion_tokens={completion_tokens} total_tokens={total_tokens}', flush=True)
42-
43-
if output and hasattr(output, 'choices') and output.choices and len(output.choices) > 0:
44-
choice = output.choices[0]
45-
if choice and hasattr(choice, 'message') and choice.message:
46-
message = choice.message
47-
content = getattr(message, 'content', None)
48-
if content:
49-
print(f'Output response: {content}', flush=True)
50-
else:
51-
print(f'Output response: {message}', flush=True)
52-
else:
53-
print(f'Output response: {choice}', flush=True)
54-
else:
55-
print('No choices in output', flush=True)
56-
print(f'Output response: {output}', flush=True)
57-
else:
58-
print('No outputs found in response', flush=True)
59-
print(f'Response data: {response}', flush=True)
60-
except Exception as e:
61-
print(f'Error: {e}', file=sys.stderr, flush=True)
62-
sys.exit(1)
27+
response = d.converse_alpha2(name=provider_component, inputs=inputs, temperature=0.7, context_id='chat-123')
28+
29+
for output in response.outputs:
30+
print(f'Output response: {output.choices[0].message.content}')

conversation/python/sdk/conversation/tool_calling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from dapr.clients.grpc import conversation
1515

1616
with DaprClient() as d:
17-
provider_component = "ollama"
17+
provider_component = "echo"
1818

1919
# ------------------------------------------------------------
2020
# Creating Tool Function definition using lower level API and hand-crafted JSON schema

0 commit comments

Comments
 (0)