gitcode-api 1.2.9__py3-none-any.whl → 1.2.10__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.
gitcode_api/llm/jiuwen.py CHANGED
@@ -11,6 +11,7 @@ from ._tool import TOOL_DESCRIPTION, TOOL_NAME, TOOL_PARAMETERS, GitCodeLLMTool
11
11
  if TYPE_CHECKING:
12
12
  from openjiuwen.core.foundation.tool import LocalFunction
13
13
 
14
+
14
15
  def _missing_openjiuwen_error() -> ImportError:
15
16
  return ImportError(
16
17
  "The openJiuwen tool support requires the optional dependency: pip install openjiuwen. "
gitcode_api/llm/openai.py CHANGED
@@ -1,7 +1,8 @@
1
1
  """OpenAI tool adapter for the GitCode SDK."""
2
2
 
3
+ import json
3
4
  from functools import cached_property
4
- from typing import Any, Dict, Optional
5
+ from typing import Any, Coroutine, Dict, Union
5
6
 
6
7
  from ._tool import TOOL_DESCRIPTION, TOOL_NAME, TOOL_PARAMETERS, GitCodeLLMTool
7
8
 
@@ -10,25 +11,21 @@ class GitCodeOpenAITool(GitCodeLLMTool):
10
11
  """OpenAI-compatible callable tool for invoking GitCode SDK resources.
11
12
 
12
13
  :param async_mode: When true, calling the instance returns the async tool coroutine.
13
- :param kwargs: Forwarded to :class:`gitcode_api.llm.GitCodeLLMTool`. ``{"async": True}``
14
- is also accepted for frameworks that construct tools from dictionaries.
14
+ :param indent: ``indent`` argument passed to :func:`json.dumps` when serializing
15
+ invocation results (default ``2``).
16
+ :param kwargs: Passed to :class:`gitcode_api.llm.GitCodeLLMTool` ---
17
+ ``client``, ``async_client``, ``api_key``, ``owner``, ``repo``, ``base_url``, ``timeout``, ``decrypt``.
15
18
  """
16
19
 
17
20
  name = TOOL_NAME
18
21
  description = TOOL_DESCRIPTION
19
22
  parameters = TOOL_PARAMETERS
20
23
 
21
- def __init__(self, async_mode: Optional[bool] = None, **kwargs) -> None:
24
+ def __init__(self, async_mode: bool = False, indent: int = 2, **kwargs) -> None:
22
25
  """Create an OpenAI tool wrapper."""
23
- async_kw = kwargs.pop("async", None)
24
- if async_mode is None:
25
- async_mode = bool(async_kw)
26
- elif async_kw is not None:
27
- raise TypeError("Pass only one of async_mode or async")
26
+ self.indent = indent
28
27
  self.async_mode = bool(async_mode)
29
28
  super().__init__(**kwargs)
30
- if self.async_mode:
31
- self.__call__ = self.__async_call__ # type: ignore[method-assign]
32
29
 
33
30
  @cached_property
34
31
  def tool(self) -> Dict[str, Any]:
@@ -46,11 +43,15 @@ class GitCodeOpenAITool(GitCodeLLMTool):
46
43
  """Return this tool in OpenAI Chat Completions tool format."""
47
44
  return self.tool
48
45
 
49
- def __call__(self, *args: Any, **kwargs) -> Any:
46
+ async def __async_call__(self, *args, **kwargs) -> str:
47
+ result = await super().__async_call__(*args, **kwargs)
48
+ return json.dumps(result, ensure_ascii=False, indent=self.indent)
49
+
50
+ def __call__(self, *args, **kwargs) -> Union[str, Coroutine[Any, Any, str]]:
50
51
  """Invoke the configured sync or async tool callable."""
51
52
  if self.async_mode:
52
53
  return self.__async_call__(*args, **kwargs)
53
- return super().__call__(*args, **kwargs)
54
+ return json.dumps(super().__call__(*args, **kwargs), ensure_ascii=False, indent=self.indent)
54
55
 
55
56
 
56
57
  __all__ = ["GitCodeOpenAITool"]
gitcode_api/version.txt CHANGED
@@ -1 +1 @@
1
- 1.2.9
1
+ 1.2.10
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitcode-api
3
- Version: 1.2.9
3
+ Version: 1.2.10
4
4
  Summary: Easy to use Python SDK for the GitCode REST API. Providing builtin CLI tool, and optional LLM integration (MCP, OpenAI tool, and openJiuwen tool) for agents. Community-maintained.
5
5
  Author-email: Hugo Huang <hugo@hugohuang.com>
6
6
  License-Expression: MIT
@@ -240,11 +240,11 @@ The `gitcode_api.llm` module exposes a single logical tool, **`gitcode_api_tool`
240
240
  | `params` | Keyword arguments for the method as a JSON object; omitted or `null` is treated as `{}`. |
241
241
  | `help` | When `true`, returns formatted help (available methods or a target signature) instead of performing a normal API call where applicable. |
242
242
 
243
- Successful results are JSON-friendly (`APIObject.to_dict()`, base64-wrapped `bytes`, and similar). Failures are returned as objects with `"error": true` and a `"message"` string (HTTP and configuration errors include extra fields when available).
243
+ Tool payloads are JSON-serialized strings: successes look like plain objects (`APIObject.to_dict()`, base64-wrapped `bytes`, and similar); failures use `"error": true`, a `"message"` string, and optional extra fields on HTTP/configuration errors.
244
244
 
245
245
  ### OpenAI tool (`GitCodeOpenAITool`)
246
246
 
247
- No extra dependencies beyond the core package. Build a Chat Completions–style tool definition with `.tool` or `.to_dict()`, then invoke the same instance with the arguments above (sync) or configure async mode for `await`.
247
+ No extra dependencies beyond the core package. Build a Chat Completions–style tool definition with `.tool` or `.to_dict()`, then invoke the same instance with the arguments above (sync) or configure async mode for `await`. Each invocation applies `json.dumps` to payload so the return type is **always `str`**. The default keyword argument `indent=2` pretty-prints JSON; pass `indent=None` for a compact single-line string.
248
248
 
249
249
  ```python
250
250
  from gitcode_api.llm import GitCodeOpenAITool
@@ -265,33 +265,43 @@ and handle tool calls directly:
265
265
 
266
266
  ```python
267
267
  import json
268
- from openai import OpenAI
269
- from gitcode_api.llm import GitCodeOpenAITool
268
+ import os
269
+ from typing import Dict, List
270
270
 
271
- tools = {
272
- "gitcode_api_tool": GitCodeOpenAITool(owner="SushiNinja", repo="GitCode-API"),
273
- }
274
- client = OpenAI(
275
- api_key="your-openai-compatible-api-key",
276
- base_url="https://your-openai-compatible-base-url/v1",
277
- )
271
+ from openai import OpenAI
278
272
 
279
- response = client.chat.completions.create(
280
- model="gpt-4.1-mini",
281
- messages=[{"role": "user", "content": "List the last 5 commits."}],
282
- tools=[tools["gitcode_api_tool"].tool],
283
- )
273
+ from gitcode_api.llm import GitCodeOpenAITool
284
274
 
285
- for tool_call in response.choices[0].message.tool_calls:
286
- selected_tool = tools[tool_call.function.name]
287
- print(f"Calling tool {tool_call.function.name}({tool_call.function.arguments}):")
288
- print("---result---")
289
- print(selected_tool(**json.loads(tool_call.function.arguments)))
290
- print("---result---")
275
+ MESSAGE_SEP = "\n" + "=" * 60 + "\n"
276
+ USER_QUERY = "List the repos owned by SushiNinja."
277
+ CONVERSATION: List[Dict[str, str]] = [dict(role="user", content=USER_QUERY)]
278
+
279
+ tools = {"gitcode_api_tool": GitCodeOpenAITool()}
280
+ client = OpenAI()
281
+
282
+ print("U:\n" + USER_QUERY + MESSAGE_SEP)
283
+ while True:
284
+ response = (
285
+ client.chat.completions.create(
286
+ model="gpt-5.4-nano",
287
+ messages=CONVERSATION,
288
+ tools=[tools["gitcode_api_tool"].tool],
289
+ )
290
+ .choices[0]
291
+ .message
292
+ )
293
+ CONVERSATION.append(response.to_dict())
294
+ print("A:\n" + (response.content or ""))
295
+ for tool_call in response.tool_calls or []:
296
+ selected_tool = tools[tool_call.function.name]
297
+ result = selected_tool(**json.loads(tool_call.function.arguments))
298
+ CONVERSATION.append(dict(role="tool", tool_call_id=tool_call.id, content=result))
299
+ print(f"<Calling tool {tool_call.function.name}({tool_call.function.arguments})>")
300
+ print(MESSAGE_SEP)
301
+ if not response.tool_calls:
302
+ break
291
303
  ```
292
304
 
293
- Constructor options mirror `GitCode` / `AsyncGitCode`: `client=`, `async_client=`, `api_key=`, `owner=`, `repo=`, `base_url=`, `timeout=`, and `decrypt=`. For dict-driven setups that reserve the name `async`, you may pass `**{"async": True}` instead of `async_mode=True` (but not both).
294
-
295
305
  ### MCP server and MCP tool (FastMCP)
296
306
 
297
307
  [MCP](https://modelcontextprotocol.io) integration uses [FastMCP](https://github.com/jlowin/fastmcp). Install the optional extra (requires **Python 3.10+** because of the `fastmcp` dependency):
@@ -9,21 +9,21 @@ gitcode_api/_models.py,sha256=v-GZzCGAb3_frY6wFiQww9m271U5MigivpEHDHnoDcI,109030
9
9
  gitcode_api/cli.py,sha256=7LLDRCKJg7avaLgIwckZZC5LewSpMPWNQFFDRhAQkEs,16616
10
10
  gitcode_api/py.typed,sha256=mDShSrm8qg9qjacQc2F-rI8ATllqP6EdgHuEYxuCXZ0,7
11
11
  gitcode_api/run_mcp.py,sha256=a7zNrcAooGovzokJwTHQGj6iT4g7iltaUoD_E1KLvMg,130
12
- gitcode_api/version.txt,sha256=yNg8JnLF45fOFqLuJ1rEWRcAK5s2dl932Z8xvfge6Cg,6
12
+ gitcode_api/version.txt,sha256=QwQnXzDgdsdqvcDygPD91VN_GscAlTuhkI4ppk1TGRk,7
13
13
  gitcode_api/llm/__init__.py,sha256=7xD9jHpk0eE12J8SQ3G0SB-8A0wEUoAsdx6SOBW6OUI,1604
14
14
  gitcode_api/llm/_tool.py,sha256=mBQPYzQ-SuSWgumapcjv3pjGQfcPYt-IxUXBT5un2Lk,16239
15
- gitcode_api/llm/jiuwen.py,sha256=7AqvBH4x0sCa4LxlRdImdph22mL6eSkCE0FL5BoMwzU,3637
15
+ gitcode_api/llm/jiuwen.py,sha256=lR3uhW67ER2KdalK9NNCOVtqFFQ1o4N5ylzWM1LkA1o,3638
16
16
  gitcode_api/llm/mcp.py,sha256=eeAuEETZ4THw31wbcnQaTlZQJ-9ZolvsejQY630OqHs,5702
17
- gitcode_api/llm/openai.py,sha256=CcS3tFntzAuN2HMbbQDctb54AnasU3n3a1Jr9LWAHwM,1998
17
+ gitcode_api/llm/openai.py,sha256=cie6qmS3YzT4j-KelBgi0MNr6Cedh2uBPib8Bpje59M,2148
18
18
  gitcode_api/resources/__init__.py,sha256=nsCKW0bFDZ5ombJZxLThmO82sOuF7o4OKUMRkAmwbwk,1725
19
19
  gitcode_api/resources/_shared.py,sha256=7bCym8bIfs818SiYYrBGI7-ZtiYlxECSDG3RduInu10,5387
20
20
  gitcode_api/resources/account.py,sha256=mnc2p7wI-nBnHFNdWPNiHfmZpT6d3RDQC777gewtm4M,38801
21
21
  gitcode_api/resources/collaboration.py,sha256=8lyk78GTjVXddiE9fieutsMGovRjteGfTJcAhwLoR0M,101607
22
22
  gitcode_api/resources/misc.py,sha256=guDwh4cxbTVsSa7EivaYM3bKMJ8_Op4KucGbKEoayKE,22412
23
23
  gitcode_api/resources/repositories.py,sha256=EAK2znZhEsgVUu-NDEQslSEEYJzvb-kHuh4mW57y6sc,78178
24
- gitcode_api-1.2.9.dist-info/licenses/LICENSE,sha256=gOACXuWhMu6PJKVLr9RQbxX3HULnZIGNXCaMFJIXhoA,1067
25
- gitcode_api-1.2.9.dist-info/METADATA,sha256=01794VzZAr36F-7Eg0MeHGJuAmTSHciiUosdj18igBs,21768
26
- gitcode_api-1.2.9.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
27
- gitcode_api-1.2.9.dist-info/entry_points.txt,sha256=dIPylJcgohIE2RRIlt3In2WzcwDK8TOdkL_ReKuij4o,53
28
- gitcode_api-1.2.9.dist-info/top_level.txt,sha256=gIlg0ptyOUHJT64ajOjWIhRPYgIQnMIvnhhnesw9fxU,12
29
- gitcode_api-1.2.9.dist-info/RECORD,,
24
+ gitcode_api-1.2.10.dist-info/licenses/LICENSE,sha256=gOACXuWhMu6PJKVLr9RQbxX3HULnZIGNXCaMFJIXhoA,1067
25
+ gitcode_api-1.2.10.dist-info/METADATA,sha256=-RsrbiBw8GpiKvLmbmA42hJ7k45Rw6OlFdlq8n94oPc,22037
26
+ gitcode_api-1.2.10.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
27
+ gitcode_api-1.2.10.dist-info/entry_points.txt,sha256=dIPylJcgohIE2RRIlt3In2WzcwDK8TOdkL_ReKuij4o,53
28
+ gitcode_api-1.2.10.dist-info/top_level.txt,sha256=gIlg0ptyOUHJT64ajOjWIhRPYgIQnMIvnhhnesw9fxU,12
29
+ gitcode_api-1.2.10.dist-info/RECORD,,