Skip to content

Commit

Permalink
优化推理提示词
Browse files Browse the repository at this point in the history
使用Kernel
  • Loading branch information
239573049 committed Jan 12, 2025
1 parent 010ea4e commit 14da981
Show file tree
Hide file tree
Showing 13 changed files with 326 additions and 224 deletions.
5 changes: 5 additions & 0 deletions AutoGpt.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAssistantChatMessage_002Ecs_002Fl_003AC_0021_003FUsers_003F23957_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa5e65d8f3f3947d7a8e879035b60bf2f1be200_003F88_003Fd9073215_003FAssistantChatMessage_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAsyncTaskMethodBuilderT_002Ecs_002Fl_003AC_0021_003FUsers_003F23957_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Ffb367341658aaedd7de424d4c9189db33c4387e268dcc4011918569442ab12_003FAsyncTaskMethodBuilderT_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAsyncTaskMethodBuilder_00601_002Ecs_002Fl_003AC_0021_003FUsers_003F23957_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F24372012c6c94138bf3f496e104366ffc8f918_003F85_003Fa62566b1_003FAsyncTaskMethodBuilder_00601_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAwaitTaskContinuation_002Ecs_002Fl_003AC_0021_003FUsers_003F23957_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F24372012c6c94138bf3f496e104366ffc8f918_003Fe3_003Fea83f96b_003FAwaitTaskContinuation_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AChatClient_002Ecs_002Fl_003AC_0021_003FUsers_003F23957_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Ff2c076f103004ccf9d060bac2155d7cf216400_003Fed_003Fe48f49fb_003FChatClient_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AChatCompletionOptions_002Ecs_002Fl_003AC_0021_003FUsers_003F23957_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa5e65d8f3f3947d7a8e879035b60bf2f1be200_003F6e_003F4c62a104_003FChatCompletionOptions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AChatMessage_002Ecs_002Fl_003AC_0021_003FUsers_003F23957_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa5e65d8f3f3947d7a8e879035b60bf2f1be200_003F4e_003F3e0c9813_003FChatMessage_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEnumerable_002Ecs_002Fl_003AC_0021_003FUsers_003F23957_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fca6bf72c27214e9bbbce02bd09f96e2e848a0_003Fde_003Fa65d29e2_003FEnumerable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AExceptionDispatchInfo_002Ecs_002Fl_003AC_0021_003FUsers_003F23957_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fbd1d5c50194fea68ff3559c160230b0ab50f5acf4ce3061bffd6d62958e2182_003FExceptionDispatchInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AExecutionContext_002Ecs_002Fl_003AC_0021_003FUsers_003F23957_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F24372012c6c94138bf3f496e104366ffc8f918_003Fcc_003Fe59834e1_003FExecutionContext_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AExecutionContext_002Ecs_002Fl_003AC_0021_003FUsers_003F23957_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F9eda537f15ea23cdfae523c19e87eb303a3ded88937ae7e55919387a43f70_003FExecutionContext_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ALazy_00601_002Ecs_002Fl_003AC_0021_003FUsers_003F23957_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F24372012c6c94138bf3f496e104366ffc8f918_003F72_003F47d16d8b_003FLazy_00601_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AManualResetValueTaskSourceCore_002Ecs_002Fl_003AC_0021_003FUsers_003F23957_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F54c7741090b55397982f8feb2ecfd06a855dae959188722c9bfb01b31c2d7_003FManualResetValueTaskSourceCore_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AOpenAIClientOptions_002Ecs_002Fl_003AC_0021_003FUsers_003F23957_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa5e65d8f3f3947d7a8e879035b60bf2f1be200_003Fc5_003F9b16c65a_003FOpenAIClientOptions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AStreamingChatCompletionUpdate_002Ecs_002Fl_003AC_0021_003FUsers_003F23957_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa5e65d8f3f3947d7a8e879035b60bf2f1be200_003Fe5_003Fc94a2d0e_003FStreamingChatCompletionUpdate_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
6 changes: 5 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<VersionSuffix>10</VersionSuffix>
<VersionSuffix>11</VersionSuffix>
<VersionPrefix>1.0</VersionPrefix>
<Version>$(VersionPrefix).$(VersionSuffix)</Version>
<Authors>AIDotNet</Authors>
Expand All @@ -13,5 +13,9 @@
<RepositoryUrl>https://github.com/AIDotNet/AutoGpt</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<AssemblyVersion>$(Version)</AssemblyVersion>

<MicrosoftVersion Condition="'$(TargetFramework)' == 'net8.0'">8.0.0</MicrosoftVersion>
<MicrosoftVersion Condition="'$(TargetFramework)' == 'net9.0'">9.0.0</MicrosoftVersion>

</PropertyGroup>
</Project>
54 changes: 21 additions & 33 deletions src/AutoGpt.Tests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,38 @@

using AutoGpt;

using Microsoft.SemanticKernel;

#pragma warning disable SKEXP0010

var service = new ServiceCollection()
// .AddOpenAI((options =>
// {
// options.Endpoint = "https://api.token-ai.cn/";
// options.NumOutputs = 8;
// }));
.AddAzureOpenAI((options =>
{
options.Endpoint = "https://token-ai-east.openai.azure.com/";
options.NumOutputs = 8;
}));
// .AddOpenAI((options =>
// {
// options.Endpoint = "https://api.token-ai.cn/";
// options.NumOutputs = 8;
// }));
.AddAutoGpt((options =>
{
options.NumOutputs = 8;
}))
;

service
.AddKernel()
.AddOpenAIChatCompletion("gpt-4o-mini", new Uri("https://api.token-ai.cn/v1"),
"sk-ePuBDXM8k6nbBSdGeAewZA8HiJzgHRu7VMkqDeHoU4aYCRq6zg", "AutoGpt");

var serviceProvider = service.BuildServiceProvider();

var autoGptClient = serviceProvider.GetRequiredService<AutoGptClient>();

const string prompt =
"""
如果一只蜗牛白天爬上 10 英尺高的杆子,然后晚上从 6 英尺高的杆子上滑下来,那么蜗牛需要多少天才能到达顶端
用5升和6升的容器如何如何取3升的水
""";
// 周长为 18 英尺。 (矩形周长的公式为 P = 2 *(长度 + 宽度)。在本例中,P = 2 * (4 + 5) = 2 * 9 = 18 英尺。)
var sw = Stopwatch.StartNew();
await foreach (var make in autoGptClient.GenerateResponseAsync(
prompt, "", "gpt-4o",
500, promptHandler: (pairs) =>
{
foreach (KeyValuePair<string, string> pair in pairs)
{
if (pair.Key == "system")
{
pairs[pair.Key] =
"""
You are an expert AI assistant that explains your reasoning step by step. For each step, provide a title that describes what you're doing in that step, along with the content. Decide if you need another step or if you're ready to give the final answer. Respond in JSON format with 'title', 'content', and 'next_action' (either 'continue' or 'final_answer') keys. USE AS MANY REASONING STEPS AS POSSIBLE. AT LEAST 3. BE AWARE OF YOUR LIMITATIONS AS AN LLM AND WHAT YOU CAN AND CANNOT DO. IN YOUR REASONING, INCLUDE EXPLORATION OF ALTERNATIVE ANSWERS. CONSIDER YOU MAY BE WRONG, AND IF YOU ARE WRONG IN YOUR REASONING, WHERE IT WOULD BE. FULLY TEST ALL OTHER POSSIBILITIES. YOU CAN BE WRONG. WHEN YOU SAY YOU ARE RE-EXAMINING, ACTUALLY RE-EXAMINE, AND USE ANOTHER APPROACH TO DO SO. DO NOT JUST SAY YOU ARE RE-EXAMINING. USE AT LEAST 3 METHODS TO DERIVE THE ANSWER. USE BEST PRACTICES.
Example of a valid JSON response:
```json
{
"title": "Identifying Key Information",
"content": "To begin solving this problem, we need to carefully examine the given information and identify the crucial elements that will guide our solution process. This involves...",
"next_action": "continue"
}```
""";
}
}
}))
prompt, 1000))
{
if (make.Type == MakeResultDto.MakeResultType.FinalAnswer)
{
Expand Down
10 changes: 5 additions & 5 deletions src/AutoGpt/AutoGpt.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>AIDotNet.AutoGpt</PackageId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.32.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(MicrosoftVersion)" />
<PackageReference Include="Microsoft.Extensions.Http" Version="$(MicrosoftVersion)" />
<PackageReference Include="Microsoft.Extensions.Options" Version="$(MicrosoftVersion)" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.33.0" />
</ItemGroup>

</Project>
Loading

0 comments on commit 14da981

Please sign in to comment.