Skip to main content

RobotGPT LLM 支持Langchain

Project description

RobotGPT LLM

RobotGPT 支持langchain

Quick Install

pip install robotgpt

使用样例

agent块式输出:

from robotgpt.robotgpt import RobotGPTLLM
from langchain.agents import AgentType, initialize_agent
from langchain.tools import BaseTool, StructuredTool, Tool, tool
class CoffeeMaking:
    def inference(self):
        return "Making coffee requires a coffee machine, coffee beans, sugar packets, and paper cups."

class ImageObjectDetect:
    def inference(self, obj):
        if obj == "sugar packets":
            return "No "+obj
        return "There is a "+obj

class AskCustomer:
    def inference(self,):
        return "Hello! We don’t have any sugar packets at the moment. Do you need to add milk?"

robotgpt_api_url = "https://dataai.harix.iamidata.com/llm/api/ask"  #流式智能问答统一适配服务,从用户控制台购买https://console.openai.iamidata.com/api/apiList
model_name = "openai/gpt-3.5-turbo-0613"
robotgpt_api_token = "Your token" #https://dataai-doc.dataarobotics.com/docs/getting-started/authentication
llm = RobotGPTLLM(temperature=0, model_name=model_name,robotgpt_api_token=robotgpt_api_token,robotgpt_api_url=robotgpt_api_url)

imgObjDetect = ImageObjectDetect()
tools = [
    Tool.from_function(
        func=CoffeeMaking.inference,
        name="Coffee making",
        description="useful for when the user needs to make coffee."
        # coroutine= ... <- you can specify an async method if desired as well
    ),
    Tool.from_function(
        func=imgObjDetect.inference,
        name="Determine whether the object exists in the picture",
        description="useful for when you want to know what is inside the photo. receives object as input. The input to this tool should be a string, representing the object. "
        # coroutine= ... <- you can specify an async method if desired as well
    ),
    Tool.from_function(
        func=AskCustomer.inference,
        name="Ask the customer whether to add milk",
        description="useful for when making coffee without sugar packets, you can ask the customer whether you need to add milk. The input to this tool should be a bool, represents whether there is a sugar packet."
        # coroutine= ... <- you can specify an async method if desired as well
    ),
]
agent = initialize_agent(
    tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True
)
agent.run(
    "给我做杯咖啡"
)

块式输出:

from robotgpt.robotgpt import RobotGPTLLM
from langchain.schema import HumanMessage

robotgpt_api_url = "https://dataai.harix.iamidata.com/llm/api/ask"  #流式智能问答统一适配服务
model_name = "openai/gpt-3.5-turbo-0613"
robotgpt_api_token = "Your token" #https://dataai-doc.dataarobotics.com/docs/getting-started/authentication

llm = RobotGPTLLM(temperature=0, model_name=model_name,robotgpt_api_token=robotgpt_api_token,robotgpt_api_url=robotgpt_api_url)
resp = llm([HumanMessage(content="Write me a song about sparkling water.")])
print(resp)

流式输出:

from langchain.callbacks import StreamingStdOutCallbackHandler
from langchain.schema import HumanMessage
from robotgpt.robotgpt import RobotGPTLLM
robotgpt_api_url = "https://dataai.harix.iamidata.com/llm/api/ask"  #流式智能问答统一适配服务
model_name = "openai/gpt-3.5-turbo-0613"
robotgpt_api_token = "Your token" #https://dataai-doc.dataarobotics.com/docs/getting-started/authentication
chat = RobotGPTLLM(streaming=True, callbacks=[StreamingStdOutCallbackHandler()], temperature=0,model_name=model_name,robotgpt_api_token=robotgpt_api_token,robotgpt_api_url=robotgpt_api_url)
resp = chat([HumanMessage(content="Write me a song about sparkling water.")])
print(resp)

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

robotgpt-0.0.11.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

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

robotgpt-0.0.11-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file robotgpt-0.0.11.tar.gz.

File metadata

  • Download URL: robotgpt-0.0.11.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for robotgpt-0.0.11.tar.gz
Algorithm Hash digest
SHA256 7df8379ace437d53ad992c6cfc6b5b9dacd356946e2765d40a4e6c6a84a711d3
MD5 955037b9e8b25a8ca708c473c4ec1618
BLAKE2b-256 e90afbf9fd8552aa73f93bc7467cf94f213abf10e87fe29466d0a7fdbd0a905f

See more details on using hashes here.

File details

Details for the file robotgpt-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: robotgpt-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for robotgpt-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 c32881a6e5f969deaa5ff49b568c05849975c43a4caa9e74c7e7e1a0c280d294
MD5 4551f5195f6380bdac6b0b1e55c92fcd
BLAKE2b-256 e2ffb99d0c094081f9dc75f85e0dddad8b0ce8084a4c462c3188aad015eb6d62

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