Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzhhui committed Mar 22, 2024
1 parent 8f5cf9d commit 766a4aa
Show file tree
Hide file tree
Showing 51 changed files with 1,160 additions and 1,132 deletions.
8 changes: 4 additions & 4 deletions bin/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Hyperf\Odin\Apis\OpenAI\OpenAI;
use Hyperf\Odin\Apis\OpenAI\OpenAIConfig;
use Hyperf\Odin\Apis\RWKV\RWKVConfig;
use Hyperf\Odin\Conversation\Conversation;
use Hyperf\Odin\Conversation\ConversationBak;
use Hyperf\Odin\Memory\MessageHistory;
use function Hyperf\Support\env as env;

Expand Down Expand Up @@ -44,15 +44,15 @@ function getClient(string $type = 'azure')

$client = getClient('azure');
$conversionId = uniqid();
$conversation = new Conversation();
$conversation = new ConversationBak();
$memory = new MessageHistory();

$input = '1+2=?,然后帮我查查东莞的明天的天气情况';
//$input = '东莞明天的最高多少度?以及 1+1=?,并将计算结果赋值给x用于下一次计算,x+10=?';
$response = $conversation->chat($client, $input, 'gpt-3.5-turbo', $conversionId, $memory, [
$response = $conversation->chat($input, 'gpt-3.5-turbo', $conversionId, $memory, [
new CalculatorAction(),
new WeatherAction(),
new SearchAction()
]);
], client: $client);
echo PHP_EOL . PHP_EOL;
echo '[FINAL] AI: ' . $response;
83 changes: 0 additions & 83 deletions bin/agent.php

This file was deleted.

43 changes: 38 additions & 5 deletions bin/interactive.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,50 @@
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/

use Hyperf\Odin\Conversation\Option;
use Hyperf\Odin\Agent\OpenAIToolsAgent;
use Hyperf\Odin\Memory\MessageHistory;
use Hyperf\Odin\Prompt\Prompt;
use Hyperf\Odin\ModelMapper;
use Hyperf\Odin\Observer;
use Hyperf\Odin\Prompt\OpenAIToolsAgentPrompt;
use Hyperf\Odin\Tools\TavilySearchResults;

$container = require_once dirname(dirname(__FILE__)) . '/bin/init.php';

$llm = $container->get(\Hyperf\Odin\LLM::class);
$conversation = $llm->createConversation()->generateConversationId()->withMemory(new MessageHistory());
/** @var \Hyperf\Odin\ModelMapper $modelMapper */
$modelMapper = $container->get(ModelMapper::class);
$llm = $modelMapper->getDefaultModel();
$prompt = new OpenAIToolsAgentPrompt();
/** @var TavilySearchResults $tavilySearchResults */
$tavilySearchResults = $container->get(TavilySearchResults::class);
$tools = [
$tavilySearchResults->setUseAnswerDirectly(false)->setSearchDepth('advanced'),
];
$observer = $container->get(Observer::class);
/** @var MessageHistory $memory */
$memory = $container->get(MessageHistory::class);
$conversationId = uniqid('agent_', true);
$agent = new OpenAIToolsAgent(model: $llm, prompt: $prompt, memory: $memory, observer: $observer, tools: $tools);
while (true) {
echo 'Human: ';
$input = trim(fgets(STDIN, 1024));
$response = $conversation->chat(Prompt::input($input), '', new Option());
$isCommand = false;
switch ($input) {
case 'dump-messages':
var_dump($memory->getConversations($conversationId));
$isCommand = true;
break;
case 'enable-debug':
$agent->setDebug(true);
$isCommand = true;
break;
case 'disable-debug':
$agent->setDebug(false);
$isCommand = true;
break;
}
if ($isCommand) {
continue;
}
$response = $agent->invoke(['input' => $input], $conversationId);
echo 'AI: ' . $response . PHP_EOL;
}
2 changes: 1 addition & 1 deletion bin/unittest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function handle(string $a, string $b): string
```
PROMPT;

$llm = $container->get(\Hyperf\Odin\LLM::class);
$llm = $container->get(\Hyperf\Odin\ModelFacade::class);

echo '[AI]: ' . $llm->chat([
'system' => new SystemMessage('You are a unit test generation robot developed by the Hyperf organization. You must return content strictly in accordance with the format requirements.'),
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
"php": ">=8.0",
"ext-bcmath": "*",
"guzzlehttp/guzzle": "^7.0",
"hyperf/di": "~2.2.0 || 3.0.*",
"hyperf/config": "~2.2.0 || 3.0.*",
"hyperf/di": "^3.0.0",
"hyperf/config": "^3.0.0",
"hyperf/qdrant-client": "*",
"hyperf/support": "^3.0.0",
"yethee/tiktoken": "^0.1.2"
},
"require-dev": {
Expand Down
73 changes: 44 additions & 29 deletions config/autoload/odin.php
Original file line number Diff line number Diff line change
@@ -1,55 +1,67 @@
<?php

use Hyperf\Odin\Model\AzureOpenAIModel;
use Hyperf\Odin\Model\OpenAIModel;
use function Hyperf\Support\env;

return [
'llm' => [
'default' => 'gpt-3.5-turbo',
'default' => 'gpt-4',
// Modify this according to your needs
'models' => [
'gpt-35-turbo' => [
'name' => 'gpt-35-turbo',
'implementation' => OpenAIModel::class,
'config' => [
'api_key' => env('AZURE_OPENAI_35_TURBO_API_KEY'),
'api_base' => env('AZURE_OPENAI_35_TURBO_API_BASE'),
'api_version' => env('AZURE_OPENAI_35_TURBO_API_VERSION', '2023-08-01-preview'),
'deployment_name' => env('AZURE_OPENAI_35_TURBO_DEPLOYMENT_NAME'),
],
],
'gpt-3.5-turbo' => [
'name' => 'gpt-3.5-turbo',
'api_type' => 'azure',
'implementation' => AzureOpenAIModel::class,
'config' => [
'api_key' => env('AZURE_OPENAI_35_TURBO_API_KEY'),
'api_base' => env('AZURE_OPENAI_35_TURBO_API_BASE'),
'api_version' => env('AZURE_OPENAI_35_TURBO_API_VERSION', '2023-08-01-preview'),
'deployment_name' => env('AZURE_OPENAI_35_TURBO_DEPLOYMENT_NAME'),
],
],
'gpt-3.5-turbo-16k' => [
'name' => 'gpt-3.5-turbo-16k',
'api_type' => 'azure',
'implementation' => AzureOpenAIModel::class,
'config' => [
'api_key' => env('AZURE_OPENAI_35_TURBO_16K_API_KEY'),
'api_base' => env('AZURE_OPENAI_35_TURBO_16K_API_BASE'),
'api_version' => env('AZURE_OPENAI_35_TURBO_16K_API_VERSION', '2023-08-01-preview'),
'deployment_name' => env('AZURE_OPENAI_35_TURBO_16K_DEPLOYMENT_NAME'),
],
],
'gpt-4' => [
'name' => 'gpt-4',
'api_type' => 'azure',
'implementation' => AzureOpenAIModel::class,
'config' => [
'api_key' => env('AZURE_OPENAI_4_API_KEY'),
'api_base' => env('AZURE_OPENAI_4_API_BASE'),
'api_version' => env('AZURE_OPENAI_4_API_VERSION', '2023-08-01-preview'),
'deployment_name' => env('AZURE_OPENAI_4_DEPLOYMENT_NAME'),
],
],
'gpt-4-32k' => [
'name' => 'gpt-4-32k',
'api_type' => 'azure',
'implementation' => AzureOpenAIModel::class,
'config' => [
'api_key' => env('AZURE_OPENAI_4_32K_API_KEY'),
'api_base' => env('AZURE_OPENAI_4_32K_API_BASE'),
'api_version' => env('AZURE_OPENAI_4_32K_API_VERSION', '2023-08-01-preview'),
'deployment_name' => env('AZURE_OPENAI_4_32K_DEPLOYMENT_NAME'),
],
],
],
],
'azure' => [
'gpt-3.5-turbo' => [
'api_key' => env('AZURE_OPENAI_35_TURBO_API_KEY'),
'api_base' => env('AZURE_OPENAI_35_TURBO_API_BASE'),
'api_version' => env('AZURE_OPENAI_35_TURBO_API_VERSION', '2023-08-01-preview'),
'deployment_name' => env('AZURE_OPENAI_35_TURBO_DEPLOYMENT_NAME'),
],
'gpt-3.5-turbo-16k' => [
'api_key' => env('AZURE_OPENAI_35_TURBO_16K_API_KEY'),
'api_base' => env('AZURE_OPENAI_35_TURBO_16K_API_BASE'),
'api_version' => env('AZURE_OPENAI_35_TURBO_16K_API_VERSION', '2023-08-01-preview'),
'deployment_name' => env('AZURE_OPENAI_35_TURBO_16K_DEPLOYMENT_NAME'),
],
'gpt-4' => [
'api_key' => env('AZURE_OPENAI_4_API_KEY'),
'api_base' => env('AZURE_OPENAI_4_API_BASE'),
'api_version' => env('AZURE_OPENAI_4_API_VERSION', '2023-08-01-preview'),
'deployment_name' => env('AZURE_OPENAI_4_DEPLOYMENT_NAME'),
],
'gpt-4-32k' => [
'api_key' => env('AZURE_OPENAI_4_32K_API_KEY'),
'api_base' => env('AZURE_OPENAI_4_32K_API_BASE'),
'api_version' => env('AZURE_OPENAI_4_32K_API_VERSION', '2023-08-01-preview'),
'deployment_name' => env('AZURE_OPENAI_4_32K_DEPLOYMENT_NAME'),
],
'text-embedding-ada-002' => [
'api_key' => env('AZURE_OPENAI_TEXT_EMBEDDING_ADA_002_API_KEY'),
'api_base' => env('AZURE_OPENAI_TEXT_EMBEDDING_ADA_002_API_BASE'),
Expand All @@ -60,4 +72,7 @@
'openai' => [
'api_key' => env('OPENAI_API_KEY'),
],
'tavily' => [
'api_key' => env('TAVILY_API_KEY'),
],
];
40 changes: 40 additions & 0 deletions data/response.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Thought: The user wants to group the "建店信息表" (Store Information Table) by "大区" (Region).

Action: ModifyViews

Observation: I need to modify the view of the "建店信息表-主表" (Store Information Table - Main Table) to include the "大区" (Region) column in the groups section.

Action:

```json
{
"action": "modify_views",
"original_views": [
{
"view_type": "table",
"name": "建店信息表-主表"
}
],
"new_views": [
{
"view_type": "table",
"table_name": "建店信息表",
"name": "建店信息表-主表",
"functions": {
"filters": [],
"sorts": [],
"groups": [
{
"column": "大区"
}
]
},
"columns": []
}
]
}
```

Thought: The view has been modified to group the "建店信息表" (Store Information Table) by "大区" (Region).

Final Answer: "建店信息表" (Store Information Table) has been grouped by "大区" (Region).
49 changes: 0 additions & 49 deletions src/Action/AbstractAction.php

This file was deleted.

Loading

0 comments on commit 766a4aa

Please sign in to comment.