Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion TypeChat.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypeChat.SemanticKernel", "
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4EE943BA-EA53-4CD2-A2E3-7B2A2C61FAE3}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
README.md = README.md
EndProjectSection
EndProject
Expand Down Expand Up @@ -59,7 +60,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "package", "package", "{D23A
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypeChat.ExamplesLib", "examples\typechat.examplesLib\TypeChat.ExamplesLib.csproj", "{80304E1F-5B1A-4142-B950-78383E1D1877}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypeChat.Schema", "src\typechat.schema\TypeChat.Schema.csproj", "{3B193D73-6A6F-4666-B377-B08CCCC92A8B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypeChat.Schema", "src\typechat.schema\TypeChat.Schema.csproj", "{3B193D73-6A6F-4666-B377-B08CCCC92A8B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public TextClass(string name, string description)
/// Class name
/// </summary>
public string Name { get; private set; }

/// <summary>
/// Class description
/// The description of a class has strong influence on how the model classifies a user's input
Expand Down
5 changes: 5 additions & 0 deletions examples/typechat.examplesLib/Dialog/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public Agent(ILanguageModel model, IContextProvider? contextProvider = null)
: this(new JsonTranslator<T>(model), contextProvider)
{
}

/// <summary>
/// Create a new Agent that uses the given language model
/// By default, the agent will use an in-memory transient message history.
Expand All @@ -45,10 +46,12 @@ public Agent(JsonTranslator<T> translator, IContextProvider? contextProvider = n
/// Instructions to the model: these let you customize how the Agent will behave
/// </summary>
public Prompt Instructions => _instructions;

/// <summary>
/// The translator being used by the Agent to go to strongly typed messages
/// </summary>
public JsonTranslator<T> Translator => _translator;

/// <summary>
/// The maximum number of characters to put in a request prompt. The prompt contains
/// - the user's request
Expand Down Expand Up @@ -137,6 +140,7 @@ protected virtual Task<Message> PrepareRequestAsync(Message request, Cancellatio
{
return Task.FromResult(request);
}

/// <summary>
/// Override to customize how user context is added to the given prompt builder
/// Since the builder will limit the # of characters, you may want to do some pre processing
Expand All @@ -148,6 +152,7 @@ protected virtual Task<bool> AppendContextAsync(PromptBuilder builder, IAsyncEnu
{
return builder.AddRangeAsync(context);
}

/// <summary>
/// Invoked when a valid response was received - the response is placed in the message body
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions examples/typechat.examplesLib/Dialog/AgentWithHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public AgentWithHistory(JsonTranslator<T> translator, IMessageStream history)
/// context with every request.
/// </summary>
public IMessageStream History => _history;

/// <summary>
/// Customize how a response is transformed into a message written into history
/// If you return null, the response will not be added to the history
Expand Down
7 changes: 7 additions & 0 deletions examples/typechat.examplesLib/Dialog/IMessageStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,42 @@ public interface IMessageStream : IContextProvider
/// </summary>
/// <param name="message">message to append</param>
void Append(Message message);

/// <summary>
/// Append a message to the stream
/// </summary>
/// <param name="message">message to append</param>
Task AppendAsync(Message message);

/// <summary>
/// Return all messages in the stream
/// </summary>
/// <returns>an enumeration of messages</returns>
IEnumerable<Message> All();

/// <summary>
/// Return all messages in the stream
/// </summary>
/// <returns>An async enumeration of messages</returns>
IAsyncEnumerable<Message> AllAsync(CancellationToken cancelToken);

/// <summary>
/// Return the newest messages in the stream in order - most recent messages first
/// </summary>
/// <returns>an enumeration of messages</returns>
IEnumerable<Message> Newest();

/// <summary>
/// Return the newest messages in the stream in order - most recent messages first
/// </summary>
/// <returns>An async enumeration of messages</returns>
IAsyncEnumerable<Message> NewestAsync(CancellationToken cancelToken);

/// <summary>
/// Clear the stream
/// </summary>
void Clear();

/// <summary>
/// Close the stream
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions examples/typechat.examplesLib/Dialog/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ public Message(string from, object body)
/// Common message sources can include "User", "Assistant". See FromUser and FromAssistant methods
/// </summary>
public string Source => _source;

/// <summary>
/// Message body
/// </summary>
public object Body => _body;

/// <summary>
/// Message body type
/// </summary>

public Type BodyType => _body.GetType();

/// <summary>
/// Optional, headers/properties to add to the message. These are useful when messages are routed or persisted
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions examples/typechat.examplesLib/Dialog/MessageList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public MessageList(int capacity = 4)
/// </summary>
/// <returns>count</returns>
public int GetCount() => Count;

/// <summary>
/// All messages in this message stream
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions examples/typechat.examplesLib/Dialog/PromptBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ public PromptBuilder(int maxLength, Func<string, int, string>? substringExtracto
/// The prompt being built
/// </summary>
public Prompt Prompt => _prompt;

/// <summary>
/// Current length of the prompt in characters
/// </summary>
public int Length => _currentLength;

/// <summary>
/// Maximum allowed prompt length
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ public async IAsyncEnumerable<IPromptSection> GetContextAsync(string request, [E
yield return _messageList[matches[i]];
}
}

/// <summary>
/// Return newest messages
/// </summary>
/// <returns>an enumerable of messages</returns>
public IEnumerable<Message> Newest() => _messageList.Newest();

/// <summary>
/// Return newest messages
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions examples/typechat.examplesLib/PluginProgramTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ public PluginProgramTranslator(IKernel kernel, ModelInfo model)
/// Translator being used
/// </summary>
public ProgramTranslator Translator => _translator;

/// <summary>
/// Kernel this translator is working with
/// </summary>
public IKernel Kernel => _kernel;

/// <summary>
/// The "API" formed by the various plugins registered with the kernel
/// </summary>
public PluginApi Api => _pluginApi;

public SchemaText Schema => _pluginSchema;

public Task<Program> TranslateAsync(string input, CancellationToken cancelToken)
Expand Down
2 changes: 2 additions & 0 deletions src/typechat.program/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public Api(object apiImpl)
{

}

/// <summary>
/// Create an Api using the supplied methods + type info implemented in the given object instance
/// </summary>
Expand All @@ -40,6 +41,7 @@ public Api(ApiTypeInfo typeInfo, object apiImpl)
/// Type information for this Api
/// </summary>
public ApiTypeInfo TypeInfo => _typeInfo;

/// <summary>
/// The object that implements the Api
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/typechat.program/ApiTypeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ public ApiMethod(MethodInfo method)
/// Api method
/// </summary>
public MethodInfo Method { get; private set; }

/// <summary>
/// Method parameters
/// </summary>
public ParameterInfo[] Params { get; private set; }

/// <summary>
/// Method return type
/// </summary>
Expand Down
5 changes: 4 additions & 1 deletion src/typechat.program/JsonNodeEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static JsonNode ToJsonNode(dynamic obj)
{
return obj;
}

if (obj is dynamic[] darray)
{
JsonArray jsonArray = new JsonArray();
Expand All @@ -23,6 +24,7 @@ public static JsonNode ToJsonNode(dynamic obj)
dynamic value = darray[i];
jsonArray.Add(ToJsonNode(value));
}

return jsonArray;
}
else if (obj is Array array)
Expand All @@ -33,9 +35,10 @@ public static JsonNode ToJsonNode(dynamic obj)
dynamic value = array.GetValue(i);
jsonArray.Add(ToJsonNode(value));
}

return jsonArray;
}

return obj;
}

}
2 changes: 2 additions & 0 deletions src/typechat.schema/CodeWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ public CodeWriter WriteIndent()
/// <param name="token"></param>
/// <returns>CodeWriter</returns>
public CodeWriter Append(string token) => Write(token);

public CodeWriter Append(StringBuilder tokens) => Write(tokens);

public CodeWriter Append(char ch)
{
_writer.Write(ch);
Expand Down
2 changes: 2 additions & 0 deletions src/typechat.schema/JsonPolymorphismSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ public class JsonPolymorphismSettings
/// You can customize this using
/// </summary>
public bool IncludeDiscriminator { get; set; } = true;

/// <summary>
/// Include a comment reminding the model to emit the discriminator first
/// </summary>
public bool IncludeComment { get; set; } = true;

/// <summary>
/// Use this to customize how type discriminators are produced.
/// By default, the name of the type is used
Expand Down
5 changes: 5 additions & 0 deletions src/typechat.schema/JsonVocabAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ public string? Entries
/// The Json property name for which this is a vocabulary
/// </summary>
public string? PropertyName { get; set; }

/// <summary>
/// Should the vocabulary be emitted inline, or as a standalone type
/// </summary>
public bool Inline { get; set; } = true;

/// <summary>
/// If true, validates properties for membership in this vocabulary
/// </summary>
Expand All @@ -70,8 +72,11 @@ public string? Entries
internal IVocab? Vocab => _vocab;

internal bool HasEntries => !string.IsNullOrEmpty(_entries);

internal bool HasName => !string.IsNullOrEmpty(Name);

internal bool HasVocab => _vocab != null;

internal bool HasPropertyName => !string.IsNullOrEmpty(PropertyName);

/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions src/typechat.schema/NamedVocab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public NamedVocab(string name, Vocab vocab)
/// The name of this vocab
/// </summary>
public string Name => _name;

/// <summary>
/// The vocabulary associated with this vocab
/// </summary>
Expand All @@ -49,17 +50,20 @@ public int CompareTo(NamedVocab? other)
{
return _name.CompareTo(other._name);
}

/// <summary>
/// Checks if obj matches the vocab name
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object? obj) => _name.Equals(obj);

/// <summary>
/// Hashcode for the vocab name
/// </summary>
/// <returns></returns>
public override int GetHashCode() => _name.GetHashCode();

/// <summary>
/// Return the vocab name
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/typechat.schema/SchemaText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public SchemaText(string text, string lang)
/// </summary>
[JsonPropertyName("lang")]
public string Lang => _lang;

/// <summary>
/// The schema text
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/typechat.schema/TypeSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public TypeSchema(Type type, SchemaText schema)
_schema = schema;
_type = type;
}

/// <summary>
/// Create TypeSchema
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/typechat.schema/TypescriptExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,31 +99,37 @@ public TypescriptExporter(TypescriptWriter writer)
/// Typescript writer the exporter is using
/// </summary>
public TypescriptWriter Writer => _writer;

//
// Use this to *customize* how a .NET Type Name is mapped to a Typescript type name
// Return null if you can't map and defaults are used.
//
public Func<Type, string?> TypeNameMapper { get; set; }

/// <summary>
/// Customize how Json Polymorphism is supported in schemas
/// </summary>
public JsonPolymorphismSettings PolymorphismSettings { get; set; }

/// <summary>
/// Should export subclasses of a given type: automatically exporting type hierarchies?
/// Default is true
/// </summary>
public bool IncludeSubclasses { get; set; } = true;

/// <summary>
/// Include comments? You can provide includable comments using the [Comment] attribute
/// Default is true
/// </summary>
public bool IncludeComments { get; set; } = true;

/// <summary>
/// Export enums as string literals? Typescript allows that and in some situations, this works
/// better with the some models
/// Default is false
/// </summary>
public bool EnumsAsLiterals { get; set; } = false;

/// <summary>
/// Ignore these types during export
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/typechat.schema/Vocab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public Vocab(IVocab src)
Add(entry);
}
}

/// <summary>
/// Initialize a vocabulary
/// </summary>
Expand Down
Loading