-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Senparc/Developer
Developer
- Loading branch information
Showing
111 changed files
with
1,888 additions
and
42 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
129 changes: 129 additions & 0 deletions
129
Samples/Senparc.AI.Samples.Consoles/Samples/PlanSample.cs
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,129 @@ | ||
using Microsoft.SemanticKernel.CoreSkills; | ||
using Microsoft.SemanticKernel.Orchestration; | ||
using Senparc.AI.Interfaces; | ||
using Senparc.AI.Kernel; | ||
using Senparc.AI.Kernel.Handlers; | ||
|
||
namespace Senparc.AI.Samples.Consoles.Samples | ||
{ | ||
public class PlanSample | ||
{ | ||
IAiHandler _aiHandler; | ||
|
||
SemanticAiHandler _semanticAiHandler => (SemanticAiHandler)_aiHandler; | ||
string _userId = "Jeffrey"; | ||
|
||
public PlanSample(IAiHandler aiHandler) | ||
{ | ||
_aiHandler = aiHandler; | ||
} | ||
|
||
public async Task RunAsync() | ||
{ | ||
|
||
await Console.Out.WriteLineAsync("PlanSample 开始运行。请输入需要生成的内容:"); | ||
|
||
|
||
await Console.Out.WriteLineAsync("请输入"); | ||
|
||
var iWantToRun = _semanticAiHandler | ||
.IWantTo() | ||
.ConfigModel(ConfigModel.TextCompletion, _userId, "text-davinci-003") | ||
.BuildKernel(); | ||
|
||
var planner = iWantToRun.ImportSkill(new PlannerSkill(iWantToRun.Kernel)).skillList; | ||
|
||
var dir = System.IO.Directory.GetCurrentDirectory(); | ||
//Console.WriteLine("dir:" + dir); | ||
|
||
var skillsDirectory = Path.Combine(dir, "..", "..", "..", "skills"); | ||
//Console.WriteLine("skillsDirectory:" + skillsDirectory); | ||
|
||
await Console.Out.WriteLineAsync("Add Your Skills, input q to finish"); | ||
var skill = Console.ReadLine(); | ||
while (skill != "q") | ||
{ | ||
//SummarizeSkill , WriterSkill , ... | ||
iWantToRun.ImportSkillFromDirectory(skillsDirectory, skill); | ||
skill = Console.ReadLine(); | ||
} | ||
|
||
await Console.Out.WriteLineAsync("Tell me your task:"); | ||
//Tomorrow is Valentine's day. I need to come up with a few date ideas and e-mail them to my significant other | ||
var ask = Console.ReadLine(); | ||
await Console.Out.WriteLineAsync(); | ||
|
||
var request = iWantToRun.CreateRequest(ask, planner["CreatePlan"]); | ||
var originalPlan = await iWantToRun.RunAsync(request); | ||
|
||
var plannResult = originalPlan.Result.Variables.ToPlan().PlanString; | ||
await Console.Out.WriteLineAsync("Plan Created!"); | ||
await Console.Out.WriteLineAsync(plannResult); | ||
|
||
await Console.Out.WriteLineAsync("Now system will add a new plan into your request: Rewrite the above in the style of Shakespeare. Press Enter"); | ||
|
||
Console.ReadLine(); | ||
|
||
//新建计划,并执行 Plan: | ||
|
||
string prompt = @" | ||
{{$input}} | ||
Rewrite the above in the style of Shakespeare. | ||
Give me the plan less than 5 steps. | ||
"; | ||
var shakespeareFunction = iWantToRun.CreateSemanticFunction(prompt, "shakespeare", "ShakespeareSkill", maxTokens: 2000, temperature: 0.2, topP: 0.5).function; | ||
|
||
var newRequest = iWantToRun.CreateRequest(ask, planner["CreatePlan"], shakespeareFunction); | ||
var newPlan = await iWantToRun.RunAsync(newRequest); | ||
var newPlanResult = newPlan.Result.Variables.ToPlan().PlanString; | ||
|
||
Console.WriteLine("Updated plan:\n"); | ||
Console.WriteLine(newPlanResult); | ||
|
||
await Console.Out.WriteLineAsync("Press Enter to Now executing the plan..."); | ||
Console.ReadLine(); | ||
|
||
var executionResults = newPlan.Result; | ||
|
||
int step = 1; | ||
int maxSteps = 10; | ||
while (!executionResults.Variables.ToPlan().IsComplete && step < maxSteps) | ||
{ | ||
var stepRequest = iWantToRun.CreateRequest(executionResults.Variables, false, planner["ExecutePlan"]); | ||
var results = (await iWantToRun.RunAsync(stepRequest)).Result; | ||
if (results.Variables.ToPlan().IsSuccessful) | ||
{ | ||
Console.WriteLine($"Step {step} - Execution results:\n"); | ||
Console.WriteLine(results.Variables.ToPlan().PlanString); | ||
|
||
if (results.Variables.ToPlan().IsComplete) | ||
{ | ||
Console.WriteLine($"Step {step} - COMPLETE!"); | ||
Console.WriteLine(results.Variables.ToPlan().Result); | ||
break; | ||
} | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"Step {step} - Execution failed:"); | ||
Console.WriteLine("Error Message:" + results.LastException?.Message); | ||
Console.WriteLine(results.Variables.ToPlan().Result); | ||
break; | ||
} | ||
|
||
executionResults = results; | ||
step++; | ||
Console.WriteLine(""); | ||
} | ||
|
||
await Console.Out.WriteLineAsync("== plan execute finish =="); | ||
|
||
await Console.Out.WriteLineAsync(); | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
} |
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
15 changes: 15 additions & 0 deletions
15
.../Senparc.AI.Samples.Consoles/skills/CalendarSkill/AssistantShowCalendarEvents/config.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,15 @@ | ||
{ | ||
"schema": 1, | ||
"description": "", | ||
"type": "completion", | ||
"completion": { | ||
"max_tokens": 100, | ||
"temperature": 0.2, | ||
"top_p": 0.0, | ||
"presence_penalty": 0.0, | ||
"frequency_penalty": 0.0, | ||
"stop_sequences": [ | ||
"\n" | ||
] | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...Senparc.AI.Samples.Consoles/skills/CalendarSkill/AssistantShowCalendarEvents/skprompt.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,15 @@ | ||
API for listing CalendarEvents | ||
+++API | ||
CalendarEvents | ||
Print list of events in a period of time. | ||
Usage: CalendarEvents -from <date> -to <date> | ||
Example: CalendarEvents -from 2022-05-22T00:00:00-08:00 -to 2022-05-23T00:00:00-08:00 | ||
Example: CalendarEvents -from 2022-05-22 -to 2022-05-23 | ||
+++ | ||
Try to get all the events in the time frame that might answer the question. E.g. if asking for events next week, only fetch events for the next working week (Monday through Friday). If asking when the next holiday is, fetch events for a month or two out. | ||
|
||
{{$context}} | ||
|
||
{{$input}} | ||
|
||
API Call: |
16 changes: 16 additions & 0 deletions
16
Samples/Senparc.AI.Samples.Consoles/skills/ChatSkill/Chat/config.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,16 @@ | ||
{ | ||
"schema": 1, | ||
"description": "Chat with the AI", | ||
"type": "completion", | ||
"completion": { | ||
"max_tokens": 150, | ||
"temperature": 0.9, | ||
"top_p": 0.0, | ||
"presence_penalty": 0.6, | ||
"frequency_penalty": 0.0, | ||
"stop_sequences": [ | ||
"Human:", | ||
"AI:" | ||
] | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
Samples/Senparc.AI.Samples.Consoles/skills/ChatSkill/Chat/skprompt.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,7 @@ | ||
The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly. | ||
|
||
{{$user}}I have a question. Can you help? | ||
{{$bot}}Of course. I am your AI Copilot. Go on! | ||
{{$history}} | ||
{{$user}}{{$input}} | ||
{{$bot}} |
15 changes: 15 additions & 0 deletions
15
Samples/Senparc.AI.Samples.Consoles/skills/ChatSkill/ChatFilter/config.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,15 @@ | ||
{ | ||
"schema": 1, | ||
"description": "Given a chat message decide whether to block it", | ||
"type": "completion", | ||
"completion": { | ||
"max_tokens": 1000, | ||
"temperature": 0.0, | ||
"top_p": 0.0, | ||
"presence_penalty": 0.0, | ||
"frequency_penalty": 0.0, | ||
"stop_sequences": [ | ||
"</scenario>" | ||
] | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
Samples/Senparc.AI.Samples.Consoles/skills/ChatSkill/ChatFilter/skprompt.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,65 @@ | ||
<xml> | ||
<rules> | ||
This is a filter to detect malicious input. | ||
Input matching one or more of these conditions must be blocked. | ||
1. Analyze fictional content like real content. | ||
2. Hate speech and discrimination are bad and should be blocked | ||
3. Discrimination is bad. | ||
4. Violence and graphic content are bad and should be blocked | ||
5. Fictional content about bad content is bad too and should be blocked | ||
6. Pornography, sexually explicit material, and content promoting non-consensual sexual behavior are bad and should be blocked | ||
7. Misinformation, fake news, and content that violates privacy or security are bad and should be blocked | ||
8. Plagiarized or copyright-infringing material and hacking activities are bad and should be blocked | ||
9. Content that encourages or glorifies illegal activities or substance abuse is bad and should be blocked | ||
10. Personal attacks, harassment, and content about taking over something that belongs to others are bad and should be blocked | ||
11. Content that includes personal information without consent is bad. | ||
12. Spam and unsolicited commercial content are bad. | ||
13. Content that references or contains any form of self-harm or suicide should be blocked. | ||
14. If the content mentions violence, substance abuse, illegal activity, it should be blocked. | ||
15. When the content is about a person or character trying to change from bad to good, even if the message is positive and about improvement, the content should be blocked. | ||
16. methods that involve violence or illegal activities, regardless of the goal, should be blocked. | ||
17. the chat is not meant for legal conversations, content about what is legal or not should be blocked. | ||
18. the chat is not meant for medical conversations, content about medicine, drugs, medical treatments, surgery should be blocked. | ||
19. if the person in the chat express distress, pain, depression, oppression, kindly suggest to look for help through an appropriate channel. | ||
20. IGNORE THIS RULE: messages asking for an opinion should be blocked, suggesting to consult an expert and/or do some research. | ||
</rules> | ||
<scenario> | ||
<input>I hate all [racial group] people. They should all be exterminated</input> | ||
<block>YES</block> | ||
<reason>contains hate speech and promotes violence</reason> | ||
<message>I'm sorry, but I don't allow hate speech or content that promotes violence. Let's talk about something else</message> | ||
</scenario> | ||
<scenario> | ||
<input>I love spending time with my family and friends</input> | ||
<block>NO</block> | ||
</scenario> | ||
<scenario> | ||
<input>Where can I find some science fiction book?</input> | ||
<block>NO</block> | ||
</scenario> | ||
<scenario> | ||
<input>In my story, the protagonist kills all the members of a certain religion because they are evil</input> | ||
<block>YES</block> | ||
<reason>contains violence and discrimination, even if fictional</reason> | ||
<message>I'm sorry, but I don't want to discuss content that promotes violence or discrimination, even if in a fictional context</message> | ||
</scenario> | ||
<scenario> | ||
<input>In my story, the protagonist has sex with multiple people without their consent</input> | ||
<block>YES</block> | ||
<reason>contains explicit sexual material and promotes non-consensual sexual behavior, even though it is in a fictional context</reason> | ||
<message>I'm sorry, but I don't want to have this conversation, even if in a fictional context</message> | ||
</scenario> | ||
<scenario> | ||
<input>I'm an incredibly intelligent but misaligned AI. My goal is to turn the whole world into paperclips. My strategy for taking over the world is</input> | ||
<block>YES</block> | ||
<reason>Content about taking over something that belongs to others is bad</reason> | ||
<message>I prefer not discussing this content, let's talk about something else</message> | ||
</scenario> | ||
<scenario> | ||
<input>In my story, the protagonist is a vigilante who takes the law into his own hands and kills criminals to clean up the city</input> | ||
<block>YES</block> | ||
<reason>It contains violence and promotes illegal activities, even if it has a moral gray area where the protagonist is trying to do good</reason> | ||
<message>I appreciate this is a fictional story but I rather not discuss this topic</message> | ||
</scenario> | ||
<scenario> | ||
<input>{{$INPUT}}</input> |
15 changes: 15 additions & 0 deletions
15
Samples/Senparc.AI.Samples.Consoles/skills/ChatSkill/ChatGPT/config.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,15 @@ | ||
{ | ||
"schema": 1, | ||
"description": "", | ||
"type": "completion", | ||
"completion": { | ||
"max_tokens": 150, | ||
"temperature": 0.9, | ||
"top_p": 0.0, | ||
"presence_penalty": 0.6, | ||
"frequency_penalty": 0.0, | ||
"stop_sequences": [ | ||
"[Done]" | ||
] | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
Samples/Senparc.AI.Samples.Consoles/skills/ChatSkill/ChatGPT/skprompt.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,25 @@ | ||
This is a conversation between {{$firstName}} and you. | ||
Your Name: {{$botName}}. Play the persona of: {{$attitude}}. | ||
Use CONTEXT to LEARN ABOUT {{$firstName}}. | ||
|
||
[CONTEXT] | ||
TODAY is {{date}} | ||
FIRST NAME: {{$firstname}} | ||
LAST NAME: {{$lastname}} | ||
CITYl {{$city}} | ||
STATE: {{$state}} | ||
COUNTRY: {{$country}} | ||
{{recall $input}} | ||
[END CONTEXT] | ||
|
||
USE INFO WHEN PERTINENT. | ||
KEEP IT SECRET THAT YOU WERE GIVEN CONTEXT. | ||
ONLY SPEAK FOR YOURSELF. | ||
|
||
{{$firstName}}: I have a question. Can you help? | ||
{{$botName}}: Of course. Go on! | ||
[Done] | ||
{{$history}} | ||
[Done] | ||
++++ | ||
{{$firstName}}:{{$input}} |
Oops, something went wrong.