mirror of
https://github.com/temporal-community/temporal-ai-agent.git
synced 2026-03-16 22:48:09 +01:00
initial progress
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
from dataclasses import dataclass
|
||||
from temporalio import activity
|
||||
from ollama import chat, ChatResponse
|
||||
import json
|
||||
from temporalio.exceptions import ApplicationError
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -12,7 +14,7 @@ class OllamaPromptInput:
|
||||
class OllamaActivities:
|
||||
@activity.defn
|
||||
def prompt_ollama(self, input: OllamaPromptInput) -> str:
|
||||
model_name = "mistral"
|
||||
model_name = "qwen2.5:14b"
|
||||
messages = [
|
||||
{
|
||||
"role": "system",
|
||||
@@ -26,3 +28,16 @@ class OllamaActivities:
|
||||
|
||||
response: ChatResponse = chat(model=model_name, messages=messages)
|
||||
return response.message.content
|
||||
|
||||
@activity.defn
|
||||
def parse_tool_data(self, json_str: str) -> dict:
|
||||
"""
|
||||
Parses a JSON string into a dictionary.
|
||||
Raises a ValueError if the JSON is invalid.
|
||||
"""
|
||||
try:
|
||||
data = json.loads(json_str)
|
||||
except json.JSONDecodeError as e:
|
||||
raise ApplicationError(f"Invalid JSON: {e}")
|
||||
|
||||
return data
|
||||
|
||||
Reference in New Issue
Block a user