Skip to content

一个文心千帆平台的第三方 Python SDK。A third-party Python SDK for a WenxinWorkshop.

License

Notifications You must be signed in to change notification settings

jm12138/WenxinWorkshop-Python-SDK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WenxinWorkshop Python SDK

  • A third-party Python SDK for a WenxinWorkshop.

Quick Start

  • Install wenxinworkshop SDK

    $ pip install git+https://github.com/jm12138/WenxinWorkshop-Python-SDK
  • Import wenxinworkshop SDK

    from wenxinworkshop import LLMAPI, EmbeddingAPI, PromptTemplateAPI
    from wenxinworkshop import Message, Messages, Texts
  • Set API key and Secret key

    api_key = '...'
    secret_key = '...'
  • LLM chat

    # create a LLM API
    erniebot = LLMAPI(
        api_key=api_key,
        secret_key=secret_key,
        url=LLMAPI.ERNIEBot
    )
    
    # create a message
    message = Message(
        role='user',
        content='你好!'
    )
    
    # create messages
    messages: Messages = [message]
    
    # get response from LLM API
    response = erniebot(
        messages=messages,
        temperature=None,
        top_p=None,
        penalty_score=None,
        stream=None,
        user_id=None,
        chunk_size=512
    )
    
    # print response
    print(response)
    
    # get response stream from LLM API
    response_stream = erniebot(
        messages=messages,
        temperature=None,
        top_p=None,
        penalty_score=None,
        stream=True,
        user_id=None,
        chunk_size=512
    )
    
    # print response stream
    for item in response_stream:
        print(item, end='')
  • Embedding

    # create a Embedding API
    ernieembedding = EmbeddingAPI(
        api_key=api_key,
        secret_key=secret_key,
        url=EmbeddingAPI.EmbeddingV1
    )
    
    # create texts
    texts: Texts = [
        '你好!',
        '你好吗?',
        '你是谁?'
    ]
    
    # get embeddings from Embedding API
    response = ernieembedding(
        texts=texts,
        user_id=None
    )
    
    # print embeddings
    print(response)
  • Get prompt template

    # create a Prompt Template API
    prompttemplate = PromptTemplateAPI(
        api_key=api_key,
        secret_key=secret_key,
        url=PromptTemplateAPI.PromptTemplate
    )
    
    # get prompt template from Prompt Template API
    response = prompttemplate(
        template_id=1968,
        content='侏罗纪世界'
    )
    
    # print prompt template
    print(response)

About

一个文心千帆平台的第三方 Python SDK。A third-party Python SDK for a WenxinWorkshop.

Topics

Resources

License

Stars

Watchers

Forks

Languages