Skip to content

Commit dd832d1

Browse files
authored
fix cache error when no need to get prompt
1 parent a566f15 commit dd832d1

4 files changed

Lines changed: 12 additions & 5 deletions

File tree

cozeloop/internal/prompt/openapi.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,15 @@ def __init__(self, http_client: Client):
120120
def mpull_prompt(self, workspace_id: str, queries: List[PromptQuery]) -> List[PromptResult]:
121121
sorted_queries = sorted(queries, key=lambda x: (x.prompt_key, x.version))
122122

123+
all_prompts = []
123124
# If query count is less than or equal to the maximum batch size, execute directly
124125
if len(sorted_queries) <= MAX_PROMPT_QUERY_BATCH_SIZE:
125-
return self._do_mpull_prompt(workspace_id, sorted_queries)
126+
batch_results = self._do_mpull_prompt(workspace_id, sorted_queries)
127+
if batch_results is not None:
128+
all_prompts.extend(batch_results)
129+
return all_prompts
126130

127131
# Process large number of queries in batches
128-
all_prompts = []
129132
for i in range(0, len(sorted_queries), MAX_PROMPT_QUERY_BATCH_SIZE):
130133
batch_queries = sorted_queries[i:i + MAX_PROMPT_QUERY_BATCH_SIZE]
131134
batch_results = self._do_mpull_prompt(workspace_id, batch_queries)
@@ -135,8 +138,10 @@ def mpull_prompt(self, workspace_id: str, queries: List[PromptQuery]) -> List[Pr
135138
return all_prompts
136139

137140
def _do_mpull_prompt(self, workspace_id: str, queries: List[PromptQuery]) -> Optional[List[PromptResult]]:
141+
if not queries:
142+
return None
138143
request = MPullPromptRequest(workspace_id=workspace_id, queries=queries)
139144
response = self.http_client.post(MPULL_PROMPT_PATH, MPullPromptResponse, request)
140-
real_resp = MPullPromptResponse.parse_obj(response)
145+
real_resp = MPullPromptResponse.model_validate(response)
141146
if real_resp.data is not None:
142147
return real_resp.data.items

cozeloop/internal/prompt/prompt.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ def _prompt_format(
137137
return results
138138

139139
def _validate_variable_values_type(self, variable_defs: List[VariableDef], variables: Dict[str, PromptVariable]):
140+
if variable_defs is None:
141+
return
140142
for var_def in variable_defs:
141143
if var_def is None:
142144
continue

examples/prompt/prompt_hub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def llm_call(self, input_data):
8888

8989
# 4. Get the prompt
9090
# If no specific version is specified, the latest version of the corresponding prompt will be obtained
91-
prompt = client.get_prompt(prompt_key="test_demo", version="0.0.1")
91+
prompt = client.get_prompt(prompt_key="prompt_hub_demo", version="0.0.1")
9292
if prompt is not None:
9393
# Get messages of the prompt
9494
if prompt.prompt_template is not None:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "cozeloop"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
description = "coze loop sdk"
55
authors = ["JiangQi715 <jiangqi.rrt@bytedance.com>"]
66
license = "MIT"

0 commit comments

Comments
 (0)