Skip to main content

InsCode SDK

Project description

InsCodeAI 使用指南

简介

InsCodeAI 提供了多种功能,包括文本生成、图像生成与编辑、语音合成与识别以及 OCR 识别等。本文档将指导您如何安装和使用这些功能。

安装

要使用 InsCodeAI,请确保您的环境中已安装 Python 3.7 或更高版本。然后按照以下步骤进行安装:

  1. 安装依赖

    pip install InsCode
    
  2. 配置 API 密钥: 在代码中或环境变量中设置 api_keybase_url。例如:

    client = InsCode(api_key="test_key")
    

功能使用案例

文本生成

单次对话完成

    completion = client.chat.completions.create(
        model="qwen-plus",
        messages=[{"role": "user", "content": [
            {"type": "text", "text": "写一个冒泡排序"}
        ]}]
    )
    print(completion.model_dump_json())

图像辅助对话完成

    completion = client.chat.completions.create(
        model="qwen-vl-plus",
        messages=[{"role": "user", "content": [
            {"type": "text", "text": "这是什么"},
            {"type": "image_url",
             "image_url": {"url": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"}}
        ]}]
    )
    print(completion.model_dump_json())

流式对话完成

    completion = client.chat.completions.create(
        model="qwen-plus",
        messages=[{"role": "user", "content": [
            {"type": "text", "text": "写一个冒泡排序"}
        ]}],
        stream=True,
        stream_options={"include_usage": True}
    )
    for chunk in completion:
        print(chunk.model_dump_json())

图像辅助流式对话完成

    completion = client.chat.completions.create(
        model="qwen-vl-plus",
        messages=[{"role": "user", "content": [
            {"type": "text", "text": "这是什么"},
            {"type": "image_url",
             "image_url": {"url": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"}}
        ]}],
        stream=True,
        stream_options={"include_usage": True}
    )
    for chunk in completion:
        print(chunk.model_dump_json())

图像生成与编辑

图像生成

    completion = client.images.generate(
        model="wanx-v1",
        prompt="a cat",
        n=1,
        size="1024*1024",
        response_format="url"
    )
    print(completion)

图像编辑

    image = open("/Users/wanghan/Documents/111_small.jpeg", "rb")
    completion = client.images.edit(
        model="wanx-style-repaint-v1",
        prompt="a girl",
        image=image,
        response_format="b64_json",
        extra_body={
            "params": json.dumps({
                "input": {
                    "style_index": 3
                },
                "parameters": {
                    "test": 1234
                }
            }, ensure_ascii=False)
        }
    )
    print(completion)

语音合成与识别

语音合成 (TTS)

    with client.audio.speech.with_streaming_response.create(
        model="cosyvoice-v1",
        voice="longxiaochun",
        input="SiliconCloud 上提供的fish audio模型是基于 70 万小时多语言音频数据训练的领先文本到语音(TTS)模型,支持中文、英语、日语、德语、法语、西班牙语、韩语、阿拉伯语等多种语言,并能够音色克隆,具有非常好的实时性。",
        response_format="mp3",
    ) as response:
        response.stream_to_file("test.mp3")

语音识别

    audio_file = open("/Users/wanghan/Downloads/hello_world_female2.wav", "rb")
    transcription = client.audio.transcriptions.create(model="paraformer-v2",
                                                       file=audio_file)
    print(transcription.text)

OCR 识别

    image_file = "/Users/wanghan/Documents/123.png"
    result = client.ocr.recognize(image=image_file)
    print(result)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

inscode-0.2.3.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

InsCode-0.2.3-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file inscode-0.2.3.tar.gz.

File metadata

  • Download URL: inscode-0.2.3.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.11

File hashes

Hashes for inscode-0.2.3.tar.gz
Algorithm Hash digest
SHA256 609668af4947470792495a4815cf0f4fada89f0fcfccfc2060c0886b6bc49624
MD5 9fd82d5c88331a4937fe6031c2164528
BLAKE2b-256 d9c02f4e1b9f0b1c710f1816f0bebc4934892b6ecfb019634999c2068f66cc3c

See more details on using hashes here.

File details

Details for the file InsCode-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: InsCode-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.11

File hashes

Hashes for InsCode-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 76ed5096c204aca3ec364470236ccb33549c98f96d6942f94d1007b6316ed9bd
MD5 97538ae4f2a27d802065101f4399e1f1
BLAKE2b-256 f92a5f83658943ce23750809152b3f7d653e1e6b6a5543d231277c51939dd731

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page