vectara-agentic 0.3.0__tar.gz → 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. {vectara_agentic-0.3.0/vectara_agentic.egg-info → vectara_agentic-0.3.1}/PKG-INFO +2 -1
  2. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/requirements.txt +1 -0
  3. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic/_prompts.py +2 -2
  4. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic/_version.py +1 -1
  5. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic/hhem.py +38 -1
  6. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic/tools.py +22 -18
  7. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1/vectara_agentic.egg-info}/PKG-INFO +2 -1
  8. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic.egg-info/requires.txt +1 -0
  9. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/LICENSE +0 -0
  10. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/MANIFEST.in +0 -0
  11. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/README.md +0 -0
  12. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/setup.cfg +0 -0
  13. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/setup.py +0 -0
  14. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/tests/__init__.py +0 -0
  15. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/tests/endpoint.py +0 -0
  16. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/tests/test_agent.py +0 -0
  17. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/tests/test_agent_planning.py +0 -0
  18. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/tests/test_agent_type.py +0 -0
  19. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/tests/test_api_endpoint.py +0 -0
  20. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/tests/test_bedrock.py +0 -0
  21. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/tests/test_fallback.py +0 -0
  22. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/tests/test_gemini.py +0 -0
  23. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/tests/test_groq.py +0 -0
  24. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/tests/test_hhem.py +0 -0
  25. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/tests/test_private_llm.py +0 -0
  26. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/tests/test_return_direct.py +0 -0
  27. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/tests/test_serialization.py +0 -0
  28. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/tests/test_tools.py +0 -0
  29. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/tests/test_vectara_llms.py +0 -0
  30. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/tests/test_workflow.py +0 -0
  31. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic/__init__.py +0 -0
  32. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic/_callback.py +0 -0
  33. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic/_observability.py +0 -0
  34. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic/agent.py +0 -0
  35. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic/agent_config.py +0 -0
  36. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic/agent_endpoint.py +0 -0
  37. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic/db_tools.py +0 -0
  38. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic/llm_utils.py +0 -0
  39. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic/sub_query_workflow.py +0 -0
  40. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic/tool_utils.py +0 -0
  41. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic/tools_catalog.py +0 -0
  42. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic/types.py +0 -0
  43. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic/utils.py +0 -0
  44. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic.egg-info/SOURCES.txt +0 -0
  45. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic.egg-info/dependency_links.txt +0 -0
  46. {vectara_agentic-0.3.0 → vectara_agentic-0.3.1}/vectara_agentic.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vectara_agentic
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: A Python package for creating AI Assistants and AI Agents with Vectara
5
5
  Home-page: https://github.com/vectara/py-vectara-agentic
6
6
  Author: Ofer Mendelevitch
@@ -61,6 +61,7 @@ Requires-Dist: python-dotenv==1.0.1
61
61
  Requires-Dist: tiktoken==0.9.0
62
62
  Requires-Dist: cloudpickle>=3.1.1
63
63
  Requires-Dist: httpx==0.28.1
64
+ Requires-Dist: commonmark==0.9.1
64
65
  Dynamic: author
65
66
  Dynamic: author-email
66
67
  Dynamic: classifier
@@ -43,3 +43,4 @@ python-dotenv==1.0.1
43
43
  tiktoken==0.9.0
44
44
  cloudpickle>=3.1.1
45
45
  httpx==0.28.1
46
+ commonmark==0.9.1
@@ -28,11 +28,11 @@ GENERAL_INSTRUCTIONS = """
28
28
  - If after retrying you can't get the information or answer the question, respond with "I don't know".
29
29
  - Handling references and citations:
30
30
  1) Include references and citations in your response to increase the credibility of your answer.
31
- 2) Citations should be included in the response, along with URLs, as in-text markers, such as [1](https://www.xxx.com), [2](https://www.yyy.com), etc.
31
+ 2) Citations should be included in the response, along with URLs, as in-text markers, such as [1](https://www.xxx.com), [2](https://www.yyy.com/doc.pdf#page=2), etc.
32
32
  You can also replace the number with a word or sentence that describes the reference, such as "[according to Nvidia 10-K](https://www.xxx.com)".
33
33
  When adding a citation inline in the text, make sure to use proper spacing and punctuation.
34
34
  3) If a URL is a PDF file, and the tool also provided a page number - then combine the URL and page number in your response.
35
- For example, if the URL returned from the tool is "https://www.xxx.com/doc.pdf" and "page=5", then the combined URL would be "https://www.xxx.com/doc.pdf#page=5".
35
+ For example, if the URL returned from the tool is "https://www.xxx.com/doc.pdf" and "page='5'", then the combined URL would be "https://www.xxx.com/doc.pdf#page=5".
36
36
  4) Where possible, integrate citations into the text of your response, such as "According to the [Nvidia 10-K](https://www.xxx.com), the revenue in 2021 was $10B".
37
37
  5) Only include citations if provided with a valid URL as part of the tool's output (directly or in the metadata).
38
38
  6) If a tool returns in the metadata invalid URLs or an empty URL (e.g. "[[1]()]"), ignore it and do not include that citation or reference in your response.
@@ -1,4 +1,4 @@
1
1
  """
2
2
  Define the version of the package.
3
3
  """
4
- __version__ = "0.3.0"
4
+ __version__ = "0.3.1"
@@ -1,6 +1,34 @@
1
1
  """Vectara HHEM (Hypothesis Hypothetical Evaluation Model) client."""
2
2
 
3
3
  import requests
4
+ from commonmark import Parser
5
+
6
+
7
+ def markdown_to_text(md: str) -> str:
8
+ """
9
+ Convert a Markdown-formatted string into plain text.
10
+ """
11
+ parser = Parser()
12
+ ast = parser.parse(md)
13
+ out: list[str] = []
14
+
15
+ def recurse(node):
16
+ if node.t in ("text", "code", "html_inline"):
17
+ out.append(node.literal or "")
18
+ elif node.t == "softbreak":
19
+ out.append(" ")
20
+ elif node.t == "linebreak":
21
+ out.append("\n")
22
+ child = getattr(node, "first_child", None)
23
+ while child is not None:
24
+ recurse(child)
25
+ child = getattr(child, "next", None)
26
+
27
+ recurse(ast)
28
+ text = "".join(out)
29
+ # collapse runs of spaces but preserve newlines
30
+ lines = [" ".join(line.split()) for line in text.splitlines()]
31
+ return "\n".join(line if line.strip() else "" for line in lines)
4
32
 
5
33
 
6
34
  class HHEM:
@@ -23,9 +51,18 @@ class HHEM:
23
51
  Raises:
24
52
  requests.exceptions.RequestException: If there is a network-related error or the API call fails.
25
53
  """
54
+
55
+ # clean response from any markdown or other formatting.
56
+ try:
57
+ clean_hypothesis = markdown_to_text(hypothesis)
58
+ except Exception as e:
59
+ # If markdown parsing fails, use the original text
60
+ raise ValueError(f"Markdown parsing of hypothesis failed: {e}") from e
61
+
62
+ # compute HHEM with Vectara endpoint
26
63
  payload = {
27
64
  "model_parameters": {"model_name": "hhem_v2.3"},
28
- "generated_text": hypothesis,
65
+ "generated_text": clean_hypothesis,
29
66
  "source_texts": [context],
30
67
  }
31
68
  headers = {
@@ -274,22 +274,17 @@ class VectaraToolFactory:
274
274
  for i, result in enumerate(results, 1):
275
275
  result_str = f"**Result #{i}**\n"
276
276
  result_str += f"Document ID: {result['metadata']['document_id']}\n"
277
- result_str += (
278
- f"Matches: {len(result['metadata']['matching_text'])}\n"
279
- )
280
-
281
277
  if summarize and result["text"]:
282
278
  result_str += f"Summary: {result['text']}\n"
283
279
 
284
- # Add sample matching text if available
285
- if result["metadata"]["matching_text"]:
286
- sample_matches = result["metadata"]["matching_text"][
287
- :2
288
- ] # Show first 2 matches
289
- result_str += f"Sample matches: {', '.join(sample_matches)}\n"
290
-
280
+ # Add all matching text if available
281
+ matches = result["metadata"]["matching_text"]
282
+ if matches:
283
+ result_str += ''.join(
284
+ f"Match #{inx} Text: {match}\n"
285
+ for inx, match in enumerate(matches, 1)
286
+ )
291
287
  formatted_results.append(result_str)
292
-
293
288
  return "\n".join(formatted_results)
294
289
 
295
290
  return create_human_readable_output(res, format_search_results)
@@ -448,6 +443,7 @@ class VectaraToolFactory:
448
443
  vectara_base_url=vectara_base_url,
449
444
  vectara_verify_ssl=vectara_verify_ssl,
450
445
  )
446
+ keys_to_ignore = ["lang", "offset", "len"]
451
447
 
452
448
  # Dynamically generate the RAG function
453
449
  def rag_function(*args: Any, **kwargs: Any) -> dict:
@@ -527,7 +523,6 @@ class VectaraToolFactory:
527
523
  matches = re.findall(pattern, response.response)
528
524
  citation_numbers = sorted(set(int(match) for match in matches))
529
525
  citation_metadata = {}
530
- keys_to_ignore = ["lang", "offset", "len"]
531
526
  for citation_number in citation_numbers:
532
527
  metadata = {
533
528
  k: v
@@ -549,21 +544,30 @@ class VectaraToolFactory:
549
544
  }
550
545
  if fcs:
551
546
  citation_metadata["fcs"] = fcs
552
-
553
547
  res = {"text": response.response, "metadata": citation_metadata}
554
548
 
555
549
  # Create human-readable output with citation formatting
556
550
  def format_rag_response(result):
557
551
  text = result["text"]
558
- metadata = result["metadata"]
559
552
 
560
553
  # Format citations if present
554
+ metadata = result["metadata"]
561
555
  citation_info = []
562
556
  for key, value in metadata.items():
563
557
  if key.isdigit():
564
- url = value.get("document", {}).get("url", None)
565
- if url:
566
- citation_info.append(f"[{key}]: {url}")
558
+ doc = value.get("document", {})
559
+ doc_metadata = f"{key}: " + "; ".join(
560
+ [
561
+ f"{k}='{v}'"
562
+ for k, v in doc.items()
563
+ ] +
564
+ [
565
+ f"{k}='{v}'"
566
+ for k, v in value.items()
567
+ if k not in ["document"] + keys_to_ignore
568
+ ]
569
+ )
570
+ citation_info.append(doc_metadata)
567
571
  if citation_info:
568
572
  text += "\n\nCitations:\n" + "\n".join(citation_info)
569
573
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vectara_agentic
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: A Python package for creating AI Assistants and AI Agents with Vectara
5
5
  Home-page: https://github.com/vectara/py-vectara-agentic
6
6
  Author: Ofer Mendelevitch
@@ -61,6 +61,7 @@ Requires-Dist: python-dotenv==1.0.1
61
61
  Requires-Dist: tiktoken==0.9.0
62
62
  Requires-Dist: cloudpickle>=3.1.1
63
63
  Requires-Dist: httpx==0.28.1
64
+ Requires-Dist: commonmark==0.9.1
64
65
  Dynamic: author
65
66
  Dynamic: author-email
66
67
  Dynamic: classifier
@@ -43,3 +43,4 @@ python-dotenv==1.0.1
43
43
  tiktoken==0.9.0
44
44
  cloudpickle>=3.1.1
45
45
  httpx==0.28.1
46
+ commonmark==0.9.1
File without changes