Skip to content

Commit cab082a

Browse files
committed
Started dumnp simple example
1 parent 67b8a7a commit cab082a

File tree

21 files changed

+1360
-16
lines changed

21 files changed

+1360
-16
lines changed

01_basic/03_chain_skill_call.ipynb

Lines changed: 214 additions & 16 deletions
Large diffs are not rendered by default.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
// Use IntelliSense to find out which attributes exist for C# debugging
6+
// Use hover for the description of the existing attributes
7+
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md
8+
"name": ".NET Core Launch (console)",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
// If you have changed target frameworks, make sure to update the program path.
13+
"program": "${workspaceFolder}/bin/Debug/net7.0/SemanticKernelExperiments.dll",
14+
"args": [],
15+
"cwd": "${workspaceFolder}",
16+
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
17+
"console": "internalConsole",
18+
"stopAtEntry": false
19+
},
20+
{
21+
"name": ".NET Core Attach",
22+
"type": "coreclr",
23+
"request": "attach"
24+
}
25+
]
26+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/SemanticKernelExperiments.sln",
11+
"/property:GenerateFullPaths=true",
12+
"/consoleloggerparameters:NoSummary;ForceNoAlign"
13+
],
14+
"problemMatcher": "$msCompile"
15+
},
16+
{
17+
"label": "publish",
18+
"command": "dotnet",
19+
"type": "process",
20+
"args": [
21+
"publish",
22+
"${workspaceFolder}/SemanticKernelExperiments.sln",
23+
"/property:GenerateFullPaths=true",
24+
"/consoleloggerparameters:NoSummary;ForceNoAlign"
25+
],
26+
"problemMatcher": "$msCompile"
27+
},
28+
{
29+
"label": "watch",
30+
"command": "dotnet",
31+
"type": "process",
32+
"args": [
33+
"watch",
34+
"run",
35+
"--project",
36+
"${workspaceFolder}/SemanticKernelExperiments.sln"
37+
],
38+
"problemMatcher": "$msCompile"
39+
}
40+
]
41+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Text.Json.Serialization;
5+
6+
namespace LogIntercepting.Helper;
7+
8+
public class ApiPayload
9+
{
10+
[JsonPropertyName("messages")] public List<Message> Messages { get; set; } = null!;
11+
12+
[JsonPropertyName("temperature")] public double Temperature { get; set; }
13+
14+
[JsonPropertyName("top_p")] public double TopP { get; set; }
15+
16+
[JsonPropertyName("frequency_penalty")]
17+
public int FrequencyPenalty { get; set; }
18+
19+
[JsonPropertyName("presence_penalty")] public int PresencePenalty { get; set; }
20+
21+
[JsonPropertyName("max_tokens")] public int MaxTokens { get; set; }
22+
23+
[JsonPropertyName("stop")] public string Stop { get; set; }
24+
25+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
26+
[JsonPropertyName("functions")] public OpenAiFunctionDefinition[] Functions { get; set; }
27+
28+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
29+
[JsonPropertyName("function_call")] public object FunctionsCall { get; set; }
30+
31+
public string Dump()
32+
{
33+
StringBuilder sb = new StringBuilder();
34+
sb.AppendLine($"Temperature: {Temperature}");
35+
sb.AppendLine($"TopP: {TopP}");
36+
sb.AppendLine($"FrequencyPenalty: {FrequencyPenalty}");
37+
sb.AppendLine($"PresencePenalty: {PresencePenalty}");
38+
sb.AppendLine($"MaxTokens: {MaxTokens}");
39+
sb.AppendLine($"Stop: {Stop}");
40+
sb.AppendLine($"Messages: {Messages.Count}");
41+
foreach (var message in Messages)
42+
{
43+
sb.AppendLine($" {message.Role}: {message.Content}");
44+
}
45+
sb.AppendLine();
46+
return sb.ToString();
47+
}
48+
}
49+
50+
public class CallSpecificFunction
51+
{
52+
public CallSpecificFunction(string name)
53+
{
54+
Name = name;
55+
}
56+
57+
[JsonPropertyName("name")] public string Name { get; set; }
58+
}
59+
60+
public class ApiResponse
61+
{
62+
[JsonPropertyName("id")] public string Id { get; set; } = null!;
63+
64+
[JsonPropertyName("object")] public string Object { get; set; } = null!;
65+
66+
[JsonPropertyName("created")] public long Created { get; set; }
67+
68+
[JsonPropertyName("model")] public string Model { get; set; } = null!;
69+
70+
[JsonPropertyName("choices")] public List<Choice> Choices { get; set; } = null!;
71+
72+
[JsonPropertyName("usage")] public Usage Usage { get; set; } = null!;
73+
}
74+
75+
public class Choice
76+
{
77+
[JsonPropertyName("index")] public int Index { get; set; }
78+
79+
[JsonPropertyName("finish_reason")] public string FinishReason { get; set; } = null!;
80+
81+
[JsonPropertyName("message")] public Message Message { get; set; } = null!;
82+
}
83+
84+
public class FunctionCall
85+
{
86+
// name and argumetns properties
87+
[JsonPropertyName("name")] public String Name { get; set; } = null!;
88+
89+
[JsonPropertyName("arguments")] public String Arguments { get; set; } = null!;
90+
}
91+
92+
public class Usage
93+
{
94+
[JsonPropertyName("completion_tokens")]
95+
public int CompletionTokens { get; set; }
96+
97+
[JsonPropertyName("prompt_tokens")] public int PromptTokens { get; set; }
98+
99+
[JsonPropertyName("total_tokens")] public int TotalTokens { get; set; }
100+
}
101+
102+
public class ToolCall
103+
{
104+
[JsonPropertyName("function")]
105+
public ToolCallFunction Function { get; set; }
106+
107+
[JsonPropertyName("type")]
108+
public string Type { get; set; }
109+
110+
[JsonPropertyName("id")]
111+
public string Id { get; set; }
112+
}
113+
114+
public class ToolCallFunction
115+
{
116+
[JsonPropertyName("name")]
117+
public string Name { get; set; }
118+
119+
[JsonPropertyName("arguments")]
120+
public string Arguments { get; set; }
121+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
3+
namespace LogIntercepting.Helper;
4+
5+
public class Parameters
6+
{
7+
private int _maxResponse;
8+
private double _temperature;
9+
private double _topP;
10+
11+
public int MaxResponse
12+
{
13+
get => _maxResponse;
14+
set => _maxResponse = Math.Clamp(value, 1, 8000);
15+
}
16+
17+
public double Temperature
18+
{
19+
get => _temperature;
20+
set => _temperature = Math.Clamp(value, 0, 1);
21+
}
22+
23+
public double TopP
24+
{
25+
get => _topP;
26+
set => _topP = Math.Clamp(value, 0, 1);
27+
}
28+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
namespace LogIntercepting.Helper;
2+
3+
using System;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
7+
public static class Dotenv
8+
{
9+
private static Dictionary<string, string> envVariables;
10+
11+
static Dotenv()
12+
{
13+
envVariables = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
14+
LoadEnvFile();
15+
}
16+
17+
private static void LoadEnvFile()
18+
{
19+
string envFilePath = FindEnvFile();
20+
if (envFilePath != null)
21+
{
22+
string[] lines = File.ReadAllLines(envFilePath);
23+
foreach (string line in lines)
24+
{
25+
if (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("#"))
26+
{
27+
int equalsIndex = line.IndexOf('=');
28+
if (equalsIndex > 0)
29+
{
30+
string key = line.Substring(0, equalsIndex).Trim();
31+
string value = line.Substring(equalsIndex + 1).Trim();
32+
envVariables[key] = value;
33+
}
34+
}
35+
}
36+
}
37+
}
38+
39+
private static string FindEnvFile()
40+
{
41+
string currentDirectory = Directory.GetCurrentDirectory();
42+
while (currentDirectory != null)
43+
{
44+
string envFilePath = Path.Combine(currentDirectory, ".env");
45+
if (File.Exists(envFilePath))
46+
{
47+
return envFilePath;
48+
}
49+
currentDirectory = Directory.GetParent(currentDirectory)?.FullName;
50+
}
51+
return null;
52+
}
53+
54+
public static string Get(string key)
55+
{
56+
if (envVariables.ContainsKey(key))
57+
{
58+
return envVariables[key];
59+
}
60+
return null;
61+
}
62+
}
63+

0 commit comments

Comments
 (0)