Skip to main content

ask-api

EN DOC

说明

ask-api 是一个python框架,借助LLM(目前支持chatgpt-api)模型的代码理解能力,让你能够与你的python代码对话,提供包括但不限于如下的能力:

  • 通过提问了解函数的用途。
  • 直接通过自然语言来执行函数。
  • 将操作过程中的各种异常信息,通过自然语言的方式告知用户。
  • 与函数进行其他自由对话。

安装(待完善)

</code></pre>
<h4 id="user-content-开发计划进行中">开发计划(进行中)<a href="#user-content-开发计划进行中" aria-label="Link to heading '开发计划(进行中)'" data-heading-content="开发计划(进行中)" class="anchor"></a></h4>
<ul>
<li><input type="checkbox" checked="" disabled="" /> 基于openai的chatgpt-api,支持对python函数进行提问,了解函数的用途。</li>
<li><input type="checkbox" checked="" disabled="" /> 支持中文以及英文两种类型的prompt。</li>
<li><input type="checkbox" disabled="" /> 通过pip安装。</li>
<li><input type="checkbox" disabled="" /> 支持自定义的prompt。</li>
<li><input type="checkbox" checked="" disabled="" /> 支持通过自然语言命令来执行函数。</li>
<li><input type="checkbox" disabled="" /> 支持其他LLM模型或api作为底层算法支持</li>
</ul>
<h4 id="user-content-示例持续完善中">示例(持续完善中)<a href="#user-content-示例持续完善中" aria-label="Link to heading '示例(持续完善中)'" data-heading-content="示例(持续完善中)" class="anchor"></a></h4>
<ul>
<li>更多细节,请参考<a href="./examples/zh_askapi_example.ipynb">中文示例</a></li>
<li>示例函数</li>
</ul>
<pre><code class="language-python"># 示例函数,给定url,下载数据并保存至指定目录
import wget
import os
BASE_PATH = "./tmp/"


def download_data(url, save_path = None) -> str:
    """下载数据并保存至指定目录
    Args:
        url (_type_): 需要下载的数据的url
        save_path (_type_): 保存数据的目录
    Returns:
        str: 保存数据的目录
    """
    if save_path is None:
        save_path = wget.detect_filename(url)

    if not os.path.exists(BASE_PATH):
        os.makedirs(BASE_PATH)

    save_path = f'{BASE_PATH}/{save_path}'
    wget.download(url, save_path)
    return save_path
  • 利用ask-api对函数进行提问,了解函数的用途
from ask_api.ask_api import ask_func

# 获取函数的功能说明
session = ask_func(download_data, message="", mode='desc')

print("*" * 100)
print(session.get_current())

desc_image

  • 利用ask-api,直接通过自然语言来执行函数
# 使用自然语言调用函数
session = ask_func(download_data, message="请帮我下载这个数据:https://github.com/redis/redis/archive/7.0.9.tar.gz", mode="execute")

print(session.get_current())

execute_image

  • 函数执行为异步执行,可以通过wait_task方法等待函数执行完成
# get result of the function task
from ask_api.util.askapi_asyn import wait_task

task = session.get_current().get_task()
if task is None:
    print("task is complete!")
    print(session.get_current())
else:
    print("task is running")
    result = wait_task(task)
    print(result)

wait_task_image

  • 异常命令的处理
# 异常指令处理
session = ask_func(download_data, message="请帮我下载", mode="execute")

print(session.get_current())

invalid_message_image

  • 函数执行异常的处理
# 任务执行中异常处理
session = ask_func(download_data, message="请帮我下载这个数据:xxx.xxx", mode="execute")

print("*" * 100)
print(session.get_current())
print("*" * 100)
task = session.get_current().get_task()
result_message = wait_task(task)
print(result_message)

error_task_image

  • 与函数进行其他自由对话(TODO)

Metadata

Release files for ask-api 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ask-api 0.1.0
File Size Uploaded Provenance
ask-api-0.1.0.tar.gz 15.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ask-api 0.1.0
File Interpreter ABI Platform
ask_api-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.2 kB

Release files / ask-api-0.1.0.tar.gz

Download URL ask-api-0.1.0.tar.gz
Size 15.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0e556337617dab22ecb18d22152b6ee6305dd874c9b7383f254f42377a425250
BLAKE2b-256 checksum
How to use checksums
8029c22369577315d8769f7ca9d84df9299c95438b3388b8a57c9de378e7db2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / ask_api-0.1.0-py3-none-any.whl

Download URL ask_api-0.1.0-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b6ebab7a7df4a0c8825d5ea57a251da4128734437ca2db07e14dee6638eb1eba
BLAKE2b-256 checksum
How to use checksums
95e8f302ffc68e24014ab0c4d879c9fefffa3bd4db2f70b1d13c23d079c654bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Security for ask-api 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page