GithubHelp home page GithubHelp logo

rockchinq / callinggpt Goto Github PK

View Code? Open in Web Editor NEW
66.0 66.0 3.0 51 KB

Build your own ChatGPT plugin platform with GPT's function calling ability | func call by GPT

Python 100.00%
chatgpt func-call gpt openai

callinggpt's Introduction

Hi there 👋

🏘️ From Guilin (桂林), China. 🏘️

🏫 Undergraduate at TJUT, currently major in CS. 🏫

😍 Why not come to travel my hometown? 😍

Guilin City

Aerial photo of Guilin urban area, shot by @Cling

📦 主要项目&技术栈 PROJECTS
  • QChatGPT⭐️ (Python, LLM, Flask, PyTest, Docker, SQLite) - 支持扩展的 LLM QQ / QQ频道 机器人🤖
  • Campux⭐️ (Go, Gin, MongoDB, Redis, MinIO, Python, Vue, Vuetify, Docker) - QQ 空间校园墙自动化解决方案
  • free-one-api (Python, Flask, SQLite, Vue, ElementUI) - LLM 对话产品逆向工程接口网关
  • CallingGPT (Python, OpenAI) - 轻量级 LLM Agent 开发框架
  • qcg-center (Go, Gin, Grafana, MongoDB, Docker) - QChatGPT 的遥测服务端
  • qcg-tester (PyTest) - QChatGPT 的系统级测试工程
  • GhostJ (Java, Socket, Swing) - 基于 Socket 的远程控制平台

⭐️: 活跃维护

🗂️ 实习经历 INTERNSHIPS
  • @maimemo | 2023.7 ~ 2023.9 | Python 后端
  • @baidu | 2023.11 ~ 2024.4 | 测试开发
  • @langgenius | 2024.8 ~ ⭐️ | 后端开发

⭐️: 至今

📊 GITHUB STATS

RockChinQ

codersrank

📲 联系方式 CONTACTS

callinggpt's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

callinggpt's Issues

Process&store messages using official suggested format

if message["role"] == "system":
            formatted_messages.append(f"system: {message['content']}\n")
        elif message["role"] == "user":
            formatted_messages.append(f"user: {message['content']}\n")
        elif message["role"] == "assistant" and message.get("function_call"):
            formatted_messages.append(f"assistant: {message['function_call']}\n")
        elif message["role"] == "assistant" and not message.get("function_call"):
            formatted_messages.append(f"assistant: {message['content']}\n")
        elif message["role"] == "function":
            formatted_messages.append(f"function ({message['name']}): {message['content']}\n")

https://github.com/openai/openai-cookbook/blob/main/examples/How_to_call_functions_with_chat_models.ipynb

Noticed another minor issue:

Noticed another minor issue:

If a "from ... import ..." statement exists in the module, the imported function will also be parsed in the namespace. Not sure if it's desired, because the doc_str of the imported external functions may not follow the required format

最初由 rzc331 在 #2 (comment) 发布

async function support

Just wondering if it's possible to support async functions or is it too hard for now?

Option to bypass function excecution return msg, only show next TEXT return msg

if 'function_call' in reply_msg:
fc = reply_msg['function_call']
args = json.loads(fc['arguments'])
call_ret = self._call_function(fc['name'], args)
append_msg['role'] = 'system'
append_msg['content'] = "(Function {} called, returned: {})".format(
fc['name'],
call_ret
)
ret = {
"type": "function_call",
"func": fc['name'].replace('-', '.'),
"value": call_ret,
}

These lines of code will now excecute the corresponding function and print out the return value from the function, which is great.

I wonder if we could make a step even further: if a function call is chosen by ChatGPT, we excecute the function, and directly send back a msg to ChatGPT again with an appended msg format like this:

{
"role": "function",
"name": name_of_the_function_excecuted
"content": function_return_value
}

and we only return text reply from ChatGPT for session.ask(). (Possibly, ChatGPT can call multiple functions in a row, and the user only wants the final answer)

Args type parsing in functions

I might be wrong about this, it seems that only string-type args are now supported?

https://github.com/RockChinQ/CallingGPT/blob/e49643a7001a8d556aa6e7b535eeca9528ea12a7/CallingGPT/entities/namespace.py#L92C9-L93

I tried to implement other arg types, among which I found list to be most tricky. As my understanding, one has to recursively define the type of the element in the list, until the element is not a list (e.g. List[List[str]]). There might be same issue with dict.

If the type of element in the list is not clearly defined, there will be an error like this

InvalidRequestError                       Traceback (most recent call last)
    [... skipping hidden 1 frame]

C:\Users\CHU~1\AppData\Local\Temp/ipykernel_32712/1691176088.py in <module>
----> 1 session.ask("how's it going?")

~\PycharmProjects\catalyst\CallingGPT\CallingGPT\session\session.py in ask(self, msg)
     48 
---> 49         resp = openai.ChatCompletion.create(
     50             **args

C:\ProgramData\Miniconda3\envs\catalyst\lib\site-packages\openai\api_resources\chat_completion.py in create(cls, *args, **kwargs)
     24             try:
---> 25                 return super().create(*args, **kwargs)
     26             except TryAgain as e:

C:\ProgramData\Miniconda3\envs\catalyst\lib\site-packages\openai\api_resources\abstract\engine_api_resource.py in create(cls, api_key, api_base, api_type, request_id, api_version, organization, **params)
    152 
--> 153         response, _, api_key = requestor.request(
    154             "post",

C:\ProgramData\Miniconda3\envs\catalyst\lib\site-packages\openai\api_requestor.py in request(self, method, url, params, headers, files, stream, request_id, request_timeout)
    297         )
--> 298         resp, got_stream = self._interpret_response(result, stream)
    299         return resp, got_stream, self.api_key

C:\ProgramData\Miniconda3\envs\catalyst\lib\site-packages\openai\api_requestor.py in _interpret_response(self, result, stream)
    699             return (
--> 700                 self._interpret_response_line(
    701                     result.content.decode("utf-8"),

C:\ProgramData\Miniconda3\envs\catalyst\lib\site-packages\openai\api_requestor.py in _interpret_response_line(self, rbody, rcode, rheaders, stream)
    762         if stream_error or not 200 <= rcode < 300:
--> 763             raise self.handle_error_response(
    764                 rbody, rcode, resp.data, rheaders, stream_error=stream_error

<class 'str'>: (<class 'TypeError'>, TypeError('__str__ returned non-string (type list)'))

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
    [... skipping hidden 1 frame]

C:\ProgramData\Miniconda3\envs\catalyst\lib\site-packages\IPython\core\interactiveshell.py in showtraceback(self, exc_tuple, filename, tb_offset, exception_only, running_compiled_code)
   2080                                             value, tb, tb_offset=tb_offset)
   2081 
-> 2082                     self._showtraceback(etype, value, stb)
   2083                     if self.call_pdb:
   2084                         # drop into debugger

C:\ProgramData\Miniconda3\envs\catalyst\lib\site-packages\ipykernel\zmqshell.py in _showtraceback(self, etype, evalue, stb)
    541             'traceback' : stb,
    542             'ename' : str(etype.__name__),
--> 543             'evalue' : str(evalue),
    544         }
    545 

TypeError: __str__ returned non-string (type list)

L10N

Document localization.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.