Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding threadId to response and improving response initialiser #3

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions alkemio_virtual_contributor_engine/events/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,21 @@ def __init__(self, response: Optional[Dict[str, Any]] = None):
self.knowledge_language: Optional[str] = None
self.original_result: Optional[str] = None
self.sources: List[Source] = []
self.thread_id: Optional[str] = None

if response is not None:
try:
self.result = response["result"]
self.human_language = response["human_language"]
self.result_language = response["result_language"]
self.knowledge_language = response["knowledge_language"]
self.original_result = response["original_result"]
self.human_language = response.get("human_language", "")
self.result_language = response.get("result_language", "")
self.knowledge_language = response.get("knowledge_language", "")
self.original_result = response.get(
"original_result", response["result"]
)
self.sources = [
Source(source) for source in response.get("sources", [])
]
self.thread_id = response.get("thread_id", "")
except KeyError as e:
raise ValueError(f"Missing required field: {e}")

Expand All @@ -72,4 +76,5 @@ def to_dict(self):
"knowledgeLanguage": self.knowledge_language,
"originalResult": self.original_result,
"sources": list(map(lambda source: source.to_dict(), self.sources)),
"threadId": self.thread_id,
}
Loading