ziya 0.1.47__py3-none-any.whl → 0.1.48__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.

Potentially problematic release.


This version of ziya might be problematic. Click here for more details.

app/agents/agent.py CHANGED
@@ -1,23 +1,25 @@
1
+ import json
1
2
  import os
2
3
  import os.path
3
- from typing import List, Tuple, Set, Union
4
+ from typing import List, Tuple, Union
4
5
 
5
- import json
6
6
  import botocore
7
7
  import tiktoken
8
8
  from langchain.agents import AgentExecutor
9
9
  from langchain.agents.format_scratchpad import format_xml
10
+ from langchain.chat_models.base import BaseChatModel
10
11
  from langchain_aws import ChatBedrock
11
12
  from langchain_community.document_loaders import TextLoader
12
13
  from langchain_core.agents import AgentFinish
13
14
  from langchain_core.messages import AIMessage, HumanMessage
14
- from pydantic import BaseModel, Field
15
+ from langchain_google_genai import ChatGoogleGenerativeAI
15
16
 
17
+ from app.utils.llm_constants import MODEL_MAPPING, AgentInput, SAMPLE_QUESTION, GEMINI_PREFIX, GOOGLE_API_KEY
16
18
  from app.agents.prompts import conversational_prompt
17
- from app.utils.sanitizer_util import clean_backtick_sequences
18
-
19
19
  from app.utils.logging_utils import logger
20
20
  from app.utils.print_tree_util import print_file_tree
21
+ from app.utils.sanitizer_util import clean_backtick_sequences
22
+
21
23
 
22
24
  def clean_chat_history(chat_history: List[Tuple[str, str]]) -> List[Tuple[str, str]]:
23
25
  """Clean chat history by removing invalid messages and normalizing content."""
@@ -44,29 +46,36 @@ def parse_output(message):
44
46
  text = clean_backtick_sequences(message.content)
45
47
  return AgentFinish(return_values={"output": text}, log=text)
46
48
 
47
- aws_profile = os.environ.get("ZIYA_AWS_PROFILE")
48
- if aws_profile:
49
- logger.info(f"Using AWS Profile: {aws_profile}")
50
- else:
51
- logger.info("No AWS profile specified via --aws-profile flag, using default credentials")
52
- model_id = {
53
- "sonnet3.5": "us.anthropic.claude-3-5-sonnet-20240620-v1:0",
54
- "sonnet3.5-v2": "us.anthropic.claude-3-5-sonnet-20241022-v2:0",
55
- "opus": "us.anthropic.claude-3-opus-20240229-v1:0",
56
- "sonnet": "us.anthropic.claude-3-sonnet-20240229-v1:0",
57
- "haiku": "us.anthropic.claude-3-haiku-20240307-v1:0",
58
- }[os.environ.get("ZIYA_AWS_MODEL", "sonnet3.5-v2")]
59
- logger.info(f"Using Claude Model: {model_id}")
60
-
61
- model = ChatBedrock(
62
- model_id=model_id,
63
- model_kwargs={"max_tokens": 4096, "temperature": 0.3, "top_k": 15},
64
- credentials_profile_name=aws_profile if aws_profile else None,
65
- config=botocore.config.Config(
66
- read_timeout=900
67
- )
68
- )
69
49
 
50
+ def get_chat_model() -> BaseChatModel:
51
+ model_name = os.environ.get("ZIYA_AWS_MODEL", "sonnet3.5-v2")
52
+
53
+ logger.info(f"Using model name: {model_name}")
54
+
55
+ model_mapped_name = MODEL_MAPPING[model_name]
56
+
57
+ if model_name.startswith(GEMINI_PREFIX):
58
+ api_key = os.environ.get(GOOGLE_API_KEY)
59
+ if not api_key:
60
+ raise ValueError("%s environment variable is required for Gemini model" % GOOGLE_API_KEY)
61
+
62
+ return ChatGoogleGenerativeAI(
63
+ model=model_mapped_name,
64
+ temperature=0.2,
65
+ max_output_tokens=4096,
66
+ top_k=15,
67
+ google_api_key=api_key,
68
+ timeout=None,
69
+ verbose=True,
70
+ )
71
+ else:
72
+ aws_profile = os.environ.get("ZIYA_AWS_PROFILE", None)
73
+ return ChatBedrock(
74
+ model_id=MODEL_MAPPING[model_name],
75
+ model_kwargs={"max_tokens": 4096, "temperature": 0.3, "top_k": 15},
76
+ credentials_profile_name=aws_profile,
77
+ config=botocore.config.Config(read_timeout=900),
78
+ )
70
79
 
71
80
  def get_combined_docs_from_files(files) -> str:
72
81
  combined_contents: str = ""
@@ -86,17 +95,17 @@ def get_combined_docs_from_files(files) -> str:
86
95
  print(f"Codebase word count: {len(combined_contents.split()):,}")
87
96
  token_count = len(tiktoken.get_encoding("cl100k_base").encode(combined_contents))
88
97
  print(f"Codebase token count: {token_count:,}")
89
- print(f"Max Claude Token limit: 200,000")
90
- print("--------------------------------------------------------")
98
+ print("-" * 120)
91
99
  return combined_contents
92
100
 
93
-
94
- llm_with_stop = model.bind(stop=["</tool_input>"])
95
-
96
101
  def extract_codebase(x):
97
102
  logger.debug(f"Extracting codebase for files: {x['config'].get('files', [])}")
98
103
  return get_combined_docs_from_files(x["config"].get("files", []))
99
104
 
105
+
106
+ # Variable definitions
107
+ model = get_chat_model()
108
+ llm_with_stop = model.bind(stop=["</tool_input>"])
100
109
  agent = (
101
110
  {
102
111
  "codebase": lambda x: extract_codebase(x),
@@ -108,14 +117,6 @@ agent = (
108
117
  | llm_with_stop
109
118
  | parse_output
110
119
  )
111
-
112
-
113
- class AgentInput(BaseModel):
114
- question: str
115
- config: dict = Field({})
116
- chat_history: List[Tuple[str, str]] = Field(..., extra={"widget": {"type": "chat"}})
117
-
118
-
119
120
  agent_executor = AgentExecutor(
120
121
  agent=agent, tools=[], verbose=True, handle_parsing_errors=True
121
122
  ).with_types(input_type=AgentInput)
@@ -123,5 +124,4 @@ agent_executor = AgentExecutor(
123
124
  agent_executor = agent_executor | (lambda x: x["output"])
124
125
 
125
126
  if __name__ == "__main__":
126
- question = "How are you ?"
127
- print(agent_executor.invoke({"question": question, "chat_history": []}))
127
+ print(agent_executor.invoke({"question": SAMPLE_QUESTION, "chat_history": []}))
app/agents/prompts.py CHANGED
@@ -183,14 +183,14 @@ Codebase ends here.
183
183
 
184
184
  Remember to strictly adhere to the Git diff format guidelines provided above when suggesting code changes.
185
185
 
186
+ Intermediate Steps: {agent_scratchpad}
186
187
  """
187
-
188
+ # Putting the intermediate steps in template as Gemini does not support
189
+ # empty strings in API. agent_scratchpad is empty at the beginning of the chain
188
190
  conversational_prompt = ChatPromptTemplate.from_messages(
189
191
  [
190
192
  ("system", template),
191
- # ("system", "You are a helpful AI bot. Your name is {name}."),
192
193
  MessagesPlaceholder(variable_name="chat_history"),
193
194
  ("user", "{question}"),
194
- ("ai", "{agent_scratchpad}"),
195
195
  ]
196
196
  )
app/main.py CHANGED
@@ -4,10 +4,12 @@ import subprocess
4
4
  import sys
5
5
  from typing import Optional
6
6
 
7
+ import dotenv
7
8
  from langchain_cli.cli import serve
8
9
 
9
- from app.utils.logging_utils import logger
10
10
  from app.utils.langchain_validation_util import validate_langchain_vars
11
+ from app.utils.llm_constants import DEFAULT_PORT, MODEL_CHOICES
12
+ from app.utils.logging_utils import logger
11
13
  from app.utils.version_util import get_current_version, get_latest_version
12
14
 
13
15
 
@@ -17,14 +19,16 @@ def parse_arguments():
17
19
  help="List of files or directories to exclude (e.g., --exclude 'tst,build,*.py')")
18
20
  parser.add_argument("--profile", type=str, default=None,
19
21
  help="AWS profile to use (e.g., --profile ziya)")
20
- parser.add_argument("--model", type=str, choices=["sonnet", "sonnet3.5", "sonnet3.5-v2", "haiku", "opus"], default="sonnet3.5-v2",
22
+ parser.add_argument("--model", type=str, choices=MODEL_CHOICES, default="sonnet3.5-v2",
21
23
  help="AWS Bedrock Model to use (e.g., --model sonnet)")
22
- parser.add_argument("--port", type=int, default=6969,
24
+ parser.add_argument("--port", type=int, default=DEFAULT_PORT,
23
25
  help="Port number to run Ziya frontend on (e.g., --port 8080)")
24
26
  parser.add_argument("--version", action="store_true",
25
27
  help="Prints the version of Ziya")
26
28
  parser.add_argument("--max-depth", type=int, default=15,
27
29
  help="Maximum depth for folder structure traversal (e.g., --max-depth 20)")
30
+ parser.add_argument("--env-file", type=str,
31
+ help="Path to .env file containing API keys (e.g., --env-file .env)")
28
32
  return parser.parse_args()
29
33
 
30
34
 
@@ -38,7 +42,11 @@ def setup_environment(args):
38
42
  os.environ["ZIYA_AWS_PROFILE"] = args.profile
39
43
  if args.model:
40
44
  os.environ["ZIYA_AWS_MODEL"] = args.model
45
+ logger.info(f"Using Model: {args.model}")
41
46
  os.environ["ZIYA_MAX_DEPTH"] = str(args.max_depth)
47
+ if args.env_file:
48
+ if not dotenv.load_dotenv(args.env_file):
49
+ raise ValueError(f"Could not load environment file: {args.env_file}")
42
50
 
43
51
 
44
52
  def check_version_and_upgrade():
@@ -0,0 +1,34 @@
1
+ from typing import List, Tuple
2
+
3
+ from pydantic import BaseModel, Field
4
+
5
+
6
+ class AgentInput(BaseModel):
7
+ question: str
8
+ config: dict = Field({})
9
+ chat_history: List[Tuple[str, str]] = Field(..., extra={"widget": {"type": "chat"}})
10
+
11
+ DEFAULT_PORT = 6969
12
+
13
+ """
14
+ Model References:
15
+ - https://ai.google.dev/gemini-api/docs/models/gemini
16
+ """
17
+
18
+ MODEL_MAPPING = {
19
+ "sonnet3.5": "us.anthropic.claude-3-5-sonnet-20240620-v1:0",
20
+ "sonnet3.5-v2": "us.anthropic.claude-3-5-sonnet-20241022-v2:0",
21
+ "opus": "us.anthropic.claude-3-opus-20240229-v1:0",
22
+ "sonnet": "us.anthropic.claude-3-sonnet-20240229-v1:0",
23
+ "haiku": "us.anthropic.claude-3-haiku-20240307-v1:0",
24
+ "gemini-2.0-flash": "gemini-2.0-flash",
25
+ "gemini-2.0-pro": "gemini-2.0-pro-exp-02-05",
26
+ "gemini-2.0-think": "gemini-2.0-flash-thinking-exp-01-21",
27
+ "gemini-1.5-pro": "gemini-1.5-pro",
28
+ "gemini-1.5-flash": "gemini-1.5-flash",
29
+ }
30
+
31
+ MODEL_CHOICES = list(MODEL_MAPPING.keys())
32
+ SAMPLE_QUESTION = "How are you ?"
33
+ GEMINI_PREFIX = "gemini"
34
+ GOOGLE_API_KEY = "GOOGLE_API_KEY"
pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "ziya"
3
- version = "0.1.47"
3
+ version = "0.1.48"
4
4
  description = ""
5
5
  authors = ["Vishnu Krishnaprasad <vishnukool@gmail.com>"]
6
6
  readme = "README.md"
@@ -15,18 +15,22 @@ uvicorn = "^0.23.2"
15
15
  pydantic = "^2.9.2"
16
16
  jinja2 = "^3.1.3"
17
17
  tiktoken = "^0.8.0"
18
- boto3 = "^1.34.88"
18
+ boto3 = "1.35.75"
19
19
  langchain-aws = ">=0.2,<0.3"
20
20
  langchain = ">=0.3,<0.4"
21
21
  langgraph = ">=0.2,<0.3"
22
22
  langchainhub = ">=0.1.15"
23
23
  langchain-anthropic = ">=0.2,<0.3"
24
+ langchain-google-genai = ">=0.1.0"
24
25
  langchain-cli = ">=0.0.15"
25
26
  pydevd-pycharm = "^243.18137.19"
26
27
  langchain-community = "^0.3.1"
28
+ python-dotenv = "^1.0.1"
29
+ transformers = "^4.48.3"
27
30
 
28
31
  [tool.poetry.group.dev.dependencies]
29
32
  pytest = "^8.3.3"
33
+ black = "^23.12.1"
30
34
 
31
35
  [build-system]
32
36
  requires = ["poetry-core"]
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "files": {
3
3
  "main.css": "/static/css/main.f447c982.css",
4
- "main.js": "/static/js/main.59d11a1d.js",
4
+ "main.js": "/static/js/main.cb581e8d.js",
5
5
  "static/media/fa-solid-900.ttf": "/static/media/fa-solid-900.2582b0e4bcf85eceead0.ttf",
6
6
  "static/media/fa-brands-400.ttf": "/static/media/fa-brands-400.1815e00441357e01619e.ttf",
7
7
  "static/media/fa-solid-900.woff2": "/static/media/fa-solid-900.2463b90d9a316e4e5294.woff2",
@@ -12,10 +12,10 @@
12
12
  "static/media/fa-v4compatibility.woff2": "/static/media/fa-v4compatibility.ea8f94e1d22e0d35ccd4.woff2",
13
13
  "index.html": "/index.html",
14
14
  "main.f447c982.css.map": "/static/css/main.f447c982.css.map",
15
- "main.59d11a1d.js.map": "/static/js/main.59d11a1d.js.map"
15
+ "main.cb581e8d.js.map": "/static/js/main.cb581e8d.js.map"
16
16
  },
17
17
  "entrypoints": [
18
18
  "static/css/main.f447c982.css",
19
- "static/js/main.59d11a1d.js"
19
+ "static/js/main.cb581e8d.js"
20
20
  ]
21
21
  }
templates/index.html CHANGED
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Ziya - Code Assistant</title><link rel="icon" href="/favicon.ico" type="image/x-icon"><script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script><script>window.enableCodeApply="true",window.diffDisplayMode="pretty",window.diffViewType="unified"</script><script defer="defer" src="/static/js/main.59d11a1d.js"></script><link href="/static/css/main.f447c982.css" rel="stylesheet"></head><body><div id="root"></div></body></html>
1
+ <!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Ziya - Code Assistant</title><link rel="icon" href="/favicon.ico" type="image/x-icon"><script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script><script>window.enableCodeApply="true",window.diffDisplayMode="pretty",window.diffViewType="unified"</script><script defer="defer" src="/static/js/main.cb581e8d.js"></script><link href="/static/css/main.f447c982.css" rel="stylesheet"></head><body><div id="root"></div></body></html>