-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: openai extension refactoring * feat: adding refactor code / async.io * feat: fix refactoring bugs * fix: add manifest.json * feat: add queue logic * fix: fix issues - remove test code - prevent sending full content again - add queue logic * feat: fix parseSentence * fix: fix end_segment bug * feat: add chatflow abstraction - chatflow - refactor to simplify flow run - added event emitter for intermedium execution * feat: refactor openai, support multi data-stream data pack * feat: finalize openai extension refactoring - change asyncio.queue to AsyncQueue - change the way we abstract chatflow - use eventEmitter for easier tool notification - use queue to ensure task are processed one by one and cancellable * feat: add docs * feat: don't use private api
- Loading branch information
Showing
21 changed files
with
1,020 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from . import openai_chatgpt_addon | ||
from .log import logger | ||
|
||
logger.info("openai_chatgpt_python extension loaded") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import logging | ||
|
||
logger = logging.getLogger("openai_chatgpt_python") | ||
logger.setLevel(logging.INFO) | ||
|
||
formatter = logging.Formatter( | ||
"%(asctime)s - %(name)s - %(levelname)s - %(process)d - [%(filename)s:%(lineno)d] - %(message)s" | ||
) | ||
|
||
console_handler = logging.StreamHandler() | ||
console_handler.setFormatter(formatter) | ||
|
||
logger.addHandler(console_handler) |
93 changes: 93 additions & 0 deletions
93
agents/ten_packages/bak/openai_chatgpt_python/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
{ | ||
"type": "extension", | ||
"name": "openai_chatgpt_python", | ||
"version": "0.4.0", | ||
"dependencies": [ | ||
{ | ||
"type": "system", | ||
"name": "ten_runtime_python", | ||
"version": "0.2" | ||
} | ||
], | ||
"api": { | ||
"property": { | ||
"api_key": { | ||
"type": "string" | ||
}, | ||
"frequency_penalty": { | ||
"type": "float64" | ||
}, | ||
"presence_penalty": { | ||
"type": "float64" | ||
}, | ||
"temperature": { | ||
"type": "float64" | ||
}, | ||
"top_p": { | ||
"type": "float64" | ||
}, | ||
"model": { | ||
"type": "string" | ||
}, | ||
"max_tokens": { | ||
"type": "int64" | ||
}, | ||
"base_url": { | ||
"type": "string" | ||
}, | ||
"prompt": { | ||
"type": "string" | ||
}, | ||
"greeting": { | ||
"type": "string" | ||
}, | ||
"checking_vision_text_items": { | ||
"type": "string" | ||
}, | ||
"proxy_url": { | ||
"type": "string" | ||
}, | ||
"max_memory_length": { | ||
"type": "int64" | ||
}, | ||
"enable_tools": { | ||
"type": "bool" | ||
} | ||
}, | ||
"data_in": [ | ||
{ | ||
"name": "text_data", | ||
"property": { | ||
"text": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
], | ||
"data_out": [ | ||
{ | ||
"name": "text_data", | ||
"property": { | ||
"text": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
], | ||
"cmd_in": [ | ||
{ | ||
"name": "flush" | ||
} | ||
], | ||
"cmd_out": [ | ||
{ | ||
"name": "flush" | ||
} | ||
], | ||
"video_frame_in": [ | ||
{ | ||
"name": "video_frame" | ||
} | ||
] | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
5 changes: 5 additions & 0 deletions
5
agents/ten_packages/bak/openai_chatgpt_python/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
openai | ||
numpy | ||
requests | ||
pillow | ||
asyncio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
agents/ten_packages/extension/openai_chatgpt_python/BUILD.gn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# | ||
# | ||
# Agora Real Time Engagement | ||
# Created by Wei Hu in 2022-11. | ||
# Copyright (c) 2024 Agora IO. All rights reserved. | ||
# | ||
# | ||
import("//build/feature/ten_package.gni") | ||
|
||
ten_package("openai_chatgpt_python") { | ||
package_kind = "extension" | ||
|
||
resources = [ | ||
"__init__.py", | ||
"addon.py", | ||
"extension.py", | ||
"log.py", | ||
"manifest.json", | ||
"property.json", | ||
] | ||
} |
60 changes: 60 additions & 0 deletions
60
agents/ten_packages/extension/openai_chatgpt_python/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# openai_chatgpt_python | ||
|
||
An extension for integrating OpenAI's GPT models (e.g., GPT-4) into your application, providing configurable AI-driven features such as conversational agents, task automation, and tool integration. | ||
|
||
## Features | ||
|
||
<!-- main features introduction --> | ||
|
||
- OpenAI GPT Integration: Leverage GPT models for text processing and conversational tasks. | ||
- Configurable: Easily customize API keys, model settings, prompts, temperature, etc. | ||
- Async Queue Processing: Supports real-time message processing with task cancellation and prioritization. | ||
- Tool Support: Integrate external tools like image recognition via OpenAI's API. | ||
|
||
## API | ||
|
||
Refer to `api` definition in [manifest.json] and default values in [property.json](property.json). | ||
|
||
<!-- Additional API.md can be referred to if extra introduction needed --> | ||
|
||
| **Property** | **Type** | **Description** | | ||
|----------------------------|------------|-------------------------------------------| | ||
| `api_key` | `string` | API key for authenticating with OpenAI | | ||
| `frequency_penalty` | `float64` | Controls how much to penalize new tokens based on their existing frequency in the text so far | | ||
| `presence_penalty` | `float64` | Controls how much to penalize new tokens based on whether they appear in the text so far | | ||
| `temperature` | `float64` | Sampling temperature, higher values mean more randomness | | ||
| `top_p` | `float64` | Nucleus sampling, chooses tokens with cumulative probability `p` | | ||
| `model` | `string` | Model identifier (e.g., GPT-3.5, GPT-4) | | ||
| `max_tokens` | `int64` | Maximum number of tokens to generate | | ||
| `base_url` | `string` | API base URL | | ||
| `prompt` | `string` | Default prompt to send to the model | | ||
| `greeting` | `string` | Greeting message to be used | | ||
| `checking_vision_text_items`| `string` | Items for checking vision-based text responses | | ||
| `proxy_url` | `string` | URL of the proxy server | | ||
| `max_memory_length` | `int64` | Maximum memory length for processing | | ||
| `enable_tools` | `bool` | Flag to enable or disable external tools | | ||
|
||
### Data In: | ||
| **Name** | **Property** | **Type** | **Description** | | ||
|----------------|--------------|------------|-------------------------------| | ||
| `text_data` | `text` | `string` | Incoming text data | | ||
|
||
### Data Out: | ||
| **Name** | **Property** | **Type** | **Description** | | ||
|----------------|--------------|------------|-------------------------------| | ||
| `text_data` | `text` | `string` | Outgoing text data | | ||
|
||
### Command In: | ||
| **Name** | **Description** | | ||
|----------------|---------------------------------------------| | ||
| `flush` | Command to flush the current processing state | | ||
|
||
### Command Out: | ||
| **Name** | **Description** | | ||
|----------------|---------------------------------------------| | ||
| `flush` | Response after flushing the current state | | ||
|
||
### Video Frame In: | ||
| **Name** | **Description** | | ||
|------------------|-------------------------------------------| | ||
| `video_frame` | Video frame input for vision processing | |
9 changes: 8 additions & 1 deletion
9
agents/ten_packages/extension/openai_chatgpt_python/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
from . import openai_chatgpt_addon | ||
# | ||
# | ||
# Agora Real Time Engagement | ||
# Created by Wei Hu in 2024-08. | ||
# Copyright (c) 2024 Agora IO. All rights reserved. | ||
# | ||
# | ||
from . import addon | ||
from .log import logger | ||
|
||
logger.info("openai_chatgpt_python extension loaded") |
22 changes: 22 additions & 0 deletions
22
agents/ten_packages/extension/openai_chatgpt_python/addon.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# | ||
# | ||
# Agora Real Time Engagement | ||
# Created by Wei Hu in 2024-08. | ||
# Copyright (c) 2024 Agora IO. All rights reserved. | ||
# | ||
# | ||
from ten import ( | ||
Addon, | ||
register_addon_as_extension, | ||
TenEnv, | ||
) | ||
from .extension import OpenAIChatGPTExtension | ||
from .log import logger | ||
|
||
|
||
@register_addon_as_extension("openai_chatgpt_python") | ||
class OpenAIChatGPTExtensionAddon(Addon): | ||
|
||
def on_create_instance(self, ten_env: TenEnv, name: str, context) -> None: | ||
logger.info("OpenAIChatGPTExtensionAddon on_create_instance") | ||
ten_env.on_create_instance_done(OpenAIChatGPTExtension(name), context) |
Oops, something went wrong.