Skip to content

Commit

Permalink
Use dumps in with_hybrid and with_generate
Browse files Browse the repository at this point in the history
  • Loading branch information
halilbilgin committed Aug 17, 2023
1 parent 6d7e726 commit 8831fad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 14 additions & 0 deletions test/gql/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ def test_get_references(property_name: str, in_class: str, properties: List[str]
'hybrid:{query: "query", vector: [1, 2, 3], alpha: 0.5}',
),
("query", None, None, None, None, 'hybrid:{query: "query"}'),
('query "query2"', None, None, None, None, 'hybrid:{query: "query \\"query2\\""}'),
("query 'query2'", None, None, None, None, """hybrid:{query: "query 'query2'"}"""),
("query", None, None, ["prop1"], None, 'hybrid:{query: "query", properties: ["prop1"]}'),
(
"query",
Expand Down Expand Up @@ -166,6 +168,18 @@ def test_hybrid(
None,
"""generate(singleResult:{prompt:"What is the meaning of life?"}){error singleResult} """,
),
(
'What is the meaning of "life"?',
None,
None,
"""generate(singleResult:{prompt:"What is the meaning of \\"life\\"?"}){error singleResult} """,
),
(
"What is the meaning of 'life'?",
None,
None,
"""generate(singleResult:{prompt:"What is the meaning of 'life'?"}){error singleResult} """,
),
(
None,
"Explain why these magazines or newspapers are about finance",
Expand Down
8 changes: 5 additions & 3 deletions weaviate/gql/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Hybrid:
fusion_type: Optional[HybridFusion]

def __str__(self) -> str:
ret = f'query: "{util.strip_newlines(self.query)}"'
ret = f"query: {dumps(util.strip_newlines(self.query))}"
if self.vector is not None:
ret += f", vector: {self.vector}"
if self.alpha is not None:
Expand Down Expand Up @@ -1130,14 +1130,16 @@ def with_generate(
task_and_prompt = ""
if single_prompt is not None:
results.append("singleResult")
task_and_prompt += f'singleResult:{{prompt:"{util.strip_newlines(single_prompt)}"}}'
task_and_prompt += (
f"singleResult:{{prompt:{dumps(util.strip_newlines(single_prompt))}}}"
)
if grouped_task is not None or (
grouped_properties is not None and len(grouped_properties) > 0
):
results.append("groupedResult")
args = []
if grouped_task is not None:
args.append(f'task:"{util.strip_newlines(grouped_task)}"')
args.append(f"task:{dumps(util.strip_newlines(grouped_task))}")
if grouped_properties is not None and len(grouped_properties) > 0:
props = '","'.join(grouped_properties)
args.append(f'properties:["{props}"]')
Expand Down

0 comments on commit 8831fad

Please sign in to comment.