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.2.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.2-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for inscode-0.2.2.tar.gz
Algorithm Hash digest
SHA256 0bf1d9b007d7496201603c63357dbf4f4c9cc057bfdc5483a06cdb36d065638a
MD5 440af7af81a476f94a84a9652324ee72
BLAKE2b-256 b7f445fddfe0c0ee4fc6444fd841870f61f8a28b56860b9002d7913918334edd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: InsCode-0.2.2-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.10

File hashes

Hashes for InsCode-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3cbd712a57ef0ba8c5f90a4efd82332f881f8fa05a952779bb43c6b72570a3ac
MD5 f25fb0c7a570e34e0874104387ced09b
BLAKE2b-256 712e9e43441d6a7380ff035cbd5ee6906137290f23b4cbf801102fbc9bca4f0a

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