Skip to content

Commit

Permalink
fix: Released new version.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Nov 15, 2023
1 parent 2e82421 commit d038069
Show file tree
Hide file tree
Showing 16 changed files with 806 additions and 837 deletions.
2 changes: 1 addition & 1 deletion src/libs/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<PropertyGroup Label="Nuget">
<Version>1.8.2</Version>
<Version>2.0.0-alpha.0</Version>
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Authors>tryAGI and contributors</Authors>
Expand Down
35 changes: 10 additions & 25 deletions src/libs/OpenAI/Extensions/ResponseMessageExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace tryAGI.OpenAI;
using OpenAI.Chat;

namespace tryAGI.OpenAI;

/// <summary>
///
Expand All @@ -11,29 +13,12 @@ public static class ResponseMessageExtensions
/// <param name="message"></param>
/// <returns></returns>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public static ChatCompletionRequestMessage AsRequestMessage(this ChatCompletionResponseMessage message)
public static ChatRequest AsRequestMessage(this Message message)
{
message = message ?? throw new ArgumentNullException(nameof(message));

return new ChatCompletionRequestMessage
{
Role = message.Role switch
{
ChatCompletionResponseMessageRole.System => ChatCompletionRequestMessageRole.System,
ChatCompletionResponseMessageRole.User => ChatCompletionRequestMessageRole.User,
ChatCompletionResponseMessageRole.Assistant => ChatCompletionRequestMessageRole.Assistant,
ChatCompletionResponseMessageRole.Function => ChatCompletionRequestMessageRole.Function,
_ => throw new ArgumentOutOfRangeException(nameof(message), $"Unknown role: {message.Role}"),
},
Content = message.Content ?? string.Empty,
Function_call = message.Function_call != null ?
new Function_call
{
Arguments = message.Function_call.Arguments ?? string.Empty,
Name = message.Function_call.Name ?? string.Empty,
}
: null,
};
return new ChatRequest(
messages: new []{ message });
}

/// <summary>
Expand All @@ -42,11 +27,11 @@ public static ChatCompletionRequestMessage AsRequestMessage(this ChatCompletionR
/// <param name="response"></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
public static ChatCompletionResponseMessage GetFirstChoiceMessage(this CreateChatCompletionResponse response)
public static Message GetFirstChoiceMessage(this ChatResponse response)
{
response = response ?? throw new ArgumentNullException(nameof(response));

return response.Choices.First().Message ??
return response.Choices[0].Message ??
throw new ArgumentException("No message in the first choice.");
}

Expand All @@ -56,11 +41,11 @@ public static ChatCompletionResponseMessage GetFirstChoiceMessage(this CreateCha
/// <param name="response"></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
public static ChatCompletionStreamResponseDelta GetFirstChoiceDelta(this CreateChatCompletionStreamResponse response)
public static Delta GetFirstChoiceDelta(this ChatResponse response)
{
response = response ?? throw new ArgumentNullException(nameof(response));

return response.Choices.First().Delta ??
return response.Choices[0].Delta ??
throw new ArgumentException("No delta in the first choice.");
}
}
37 changes: 11 additions & 26 deletions src/libs/OpenAI/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace tryAGI.OpenAI;
using OpenAI.Chat;

namespace tryAGI.OpenAI;

/// <summary>
///
Expand All @@ -10,41 +12,29 @@ public static class StringExtensions
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
public static ChatCompletionRequestMessage AsSystemMessage(this string content)
public static Message AsSystemMessage(this string content)
{
return new ChatCompletionRequestMessage
{
Role = ChatCompletionRequestMessageRole.System,
Content = content,
};
return new Message(Role.System, content);
}

/// <summary>
///
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
public static ChatCompletionRequestMessage AsUserMessage(this string content)
public static Message AsUserMessage(this string content)
{
return new ChatCompletionRequestMessage
{
Role = ChatCompletionRequestMessageRole.User,
Content = content,
};
return new Message(Role.User, content);
}

/// <summary>
///
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
public static ChatCompletionRequestMessage AsAssistantMessage(this string content)
public static Message AsAssistantMessage(this string content)
{
return new ChatCompletionRequestMessage
{
Role = ChatCompletionRequestMessageRole.Assistant,
Content = content,
};
return new Message(Role.Assistant, content);
}

/// <summary>
Expand All @@ -53,13 +43,8 @@ public static ChatCompletionRequestMessage AsAssistantMessage(this string conten
/// <param name="json"></param>
/// <param name="name"></param>
/// <returns></returns>
public static ChatCompletionRequestMessage AsFunctionMessage(this string json, string name)
public static Message AsFunctionMessage(this string json, string name)
{
return new ChatCompletionRequestMessage
{
Role = ChatCompletionRequestMessageRole.Function,
Name = name,
Content = json,
};
return new Message(new Tool(new Function(name)), json);
}
}
Loading

0 comments on commit d038069

Please sign in to comment.