Skip to content

Commit c22ce83

Browse files
committed
support non-azure openai
1 parent fb83e9a commit c22ce83

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Lokad.Prompting/AzureOpenAICompletionClient.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,15 @@ public AzureOpenAICompletionClient(OpenAIClient client, string deployment, int t
3838
Functions = Array.Empty<FunDef>();
3939
}
4040

41+
public static AzureOpenAICompletionClient FromOpenAI(string apiKey, string model, int tokenCapacity, Action<string>? live = null)
42+
{
43+
var client = new OpenAIClient(apiKey);
44+
return new AzureOpenAICompletionClient(client, model /* model used as deployment */, tokenCapacity, live);
45+
}
46+
4147
public string GetCompletion(string prompt, CancellationToken cancel = default)
4248
{
49+
4350
return GetCompletion(prompt, Array.Empty<string>(), out var _, cancel);
4451
}
4552

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Xunit;
2+
namespace Lokad.Prompting.Tests;
3+
4+
public class NonAzureOpenAI
5+
{
6+
[Fact(Skip = "No config setup")]
7+
public void SmokeTest()
8+
{
9+
var model = "gpt-3.5-turbo";
10+
var apiKey = "sk-..";
11+
var c = AzureOpenAICompletionClient.FromOpenAI(apiKey, model, 4096);
12+
13+
var r = c.GetCompletion("compose a haiku");
14+
15+
Assert.NotNull(r);
16+
Assert.True(r.Length > 10);
17+
}
18+
}

0 commit comments

Comments
 (0)