vision-agent 0.2.91__py3-none-any.whl → 0.2.93__py3-none-any.whl

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.
@@ -1,2 +1,3 @@
1
1
  from .agent import Agent
2
- from .vision_agent import AzureVisionAgent, VisionAgent
2
+ from .vision_agent import VisionAgent
3
+ from .vision_agent_coder import AzureVisionAgentCoder, VisionAgentCoder
@@ -2,7 +2,7 @@ from abc import ABC, abstractmethod
2
2
  from pathlib import Path
3
3
  from typing import Any, Dict, List, Optional, Union
4
4
 
5
- from vision_agent.lmm import Message
5
+ from vision_agent.lmm.types import Message
6
6
 
7
7
 
8
8
  class Agent(ABC):
@@ -0,0 +1,43 @@
1
+ import json
2
+ import logging
3
+ import sys
4
+ from typing import Any, Dict
5
+
6
+ logging.basicConfig(stream=sys.stdout)
7
+ _LOGGER = logging.getLogger(__name__)
8
+
9
+
10
+ def extract_json(json_str: str) -> Dict[str, Any]:
11
+ try:
12
+ json_dict = json.loads(json_str)
13
+ except json.JSONDecodeError:
14
+ input_json_str = json_str
15
+ if "```json" in json_str:
16
+ json_str = json_str[json_str.find("```json") + len("```json") :]
17
+ json_str = json_str[: json_str.find("```")]
18
+ elif "```" in json_str:
19
+ json_str = json_str[json_str.find("```") + len("```") :]
20
+ # get the last ``` not one from an intermediate string
21
+ json_str = json_str[: json_str.find("}```")]
22
+ try:
23
+ json_dict = json.loads(json_str)
24
+ except json.JSONDecodeError as e:
25
+ error_msg = f"Could not extract JSON from the given str: {json_str}.\nFunction input:\n{input_json_str}"
26
+ _LOGGER.exception(error_msg)
27
+ raise ValueError(error_msg) from e
28
+ return json_dict # type: ignore
29
+
30
+
31
+ def extract_code(code: str) -> str:
32
+ if "\n```python" in code:
33
+ start = "\n```python"
34
+ elif "```python" in code:
35
+ start = "```python"
36
+ else:
37
+ return code
38
+
39
+ code = code[code.find(start) + len(start) :]
40
+ code = code[: code.find("```")]
41
+ if code.startswith("python\n"):
42
+ code = code[len("python\n") :]
43
+ return code