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.0.tar.gz (9.1 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.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: inscode-0.2.0.tar.gz
  • Upload date:
  • Size: 9.1 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.0.tar.gz
Algorithm Hash digest
SHA256 489fa16ab26cced3ee1daa2bfb7aced2ee9811a26dab1a5df25d8fc0ca69fe63
MD5 c2118705b152fbcbf70bf85f9df80a65
BLAKE2b-256 f449a30332e733a375aad146cd7709e69411fcad695e4c5419eb69bff5ac1c04

See more details on using hashes here.

File details

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

File metadata

  • Download URL: InsCode-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 727300abdcb5088ecf9ff02d8faa808a8f21573014cf21ed3cc42e5bbd5bdb50
MD5 33dd9383654e41ae20eee220be6208fc
BLAKE2b-256 3240fe56517a66845008520b409de1bc64a5db5921f05468727427bdf1f1232d

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