public IEnumerator EngineRetrieveCoroutine() { TestManager test = TestManager.Instance; OpenAiApiV1 api = test.CleanAndProvideApi(); ApiResult <EngineV1> result = null; yield return(api.Engines.Engine("ada").RetrieveEngineCoroutine(test, (r) => result = r)); Assert.IsNotNull(result); Assert.That(result.IsSuccess); Assert.IsNotNull(result.Result); Assert.That(result.Result.id == "ada"); }
public IEnumerator SearchSearchCoroutine() { TestManager test = TestManager.Instance; OpenAiApiV1 api = test.CleanAndProvideApi(); ApiResult <SearchListV1> result = null; SearchRequestV1 req = new SearchRequestV1() { documents = new string[] { "doc1", "doc2" }, query = "is this a doc" }; yield return(api.Engines.Engine("ada").Search.SearchCoroutine(test, req, (r) => result = r)); Assert.IsNotNull(result); Assert.That(result.IsSuccess); Assert.IsNotNull(result.Result); Assert.IsNotEmpty(result.Result.data); Assert.That(result.Result.data.Length == 2); }
// Issue: https://github.com/hexthedev/OpenAi-Api-Unity/issues/7 // Prompts weren't working with escape characters public IEnumerator Issue007_EscapeCharacterBug() { TestManager test = TestManager.Instance; OpenAiApiV1 api = test.CleanAndProvideApi(); ApiResult <CompletionV1> result = null; yield return(api.Engines.Engine("ada").Completions.CreateCompletionCoroutine( test, new CompletionRequestV1() { prompt = "something\r\n", max_tokens = 8 }, (r) => result = r )); Assert.IsNotNull(result); Assert.That(result.IsSuccess); Assert.IsNotNull(result.Result); }
public IEnumerator EngineRetrieveAsync() { TestManager test = TestManager.Instance; OpenAiApiV1 api = test.CleanAndProvideApi(); Task <ApiResult <EngineV1> > resultTask = api.Engines.Engine("ada").RetrieveEngineAsync(); while (!resultTask.IsCompleted) { yield return(new WaitForEndOfFrame()); } ApiResult <EngineV1> result = resultTask.Result; Assert.IsNotNull(result); Assert.IsTrue(result.IsSuccess); Assert.IsNotNull(result.Result); Assert.That(result.Result.id == "ada"); }
public IEnumerator EnginesListAsync() { TestManager test = TestManager.Instance; OpenAiApiV1 api = test.CleanAndProvideApi(); Task <ApiResult <EnginesListV1> > resTask = api.Engines.ListEnginesAsync(); while (!resTask.IsCompleted) { yield return(new WaitForEndOfFrame()); } ApiResult <EnginesListV1> res = resTask.Result; Assert.IsNotNull(res); Assert.That(res.IsSuccess); Assert.IsNotNull(res.Result); Assert.IsNotEmpty(res.Result.data); }
public IEnumerator CompletionsCreateCoroutine() { TestManager test = TestManager.Instance; OpenAiApiV1 api = test.CleanAndProvideApi(); ApiResult <CompletionV1> result = null; CompletionRequestV1 req = new CompletionRequestV1() { prompt = "hello", n = 8 }; yield return(api.Engines.Engine("ada").Completions.CreateCompletionCoroutine(test, req, (r) => result = r)); Assert.IsNotNull(result); Assert.That(result.IsSuccess); Assert.IsNotNull(result.Result); Assert.IsNotEmpty(result.Result.choices); Assert.That(result.Result.choices.Length > 0); }
public IEnumerator CompletionsCreateAsync() { TestManager test = TestManager.Instance; OpenAiApiV1 api = test.CleanAndProvideApi(); Task <ApiResult <CompletionV1> > resTask = api.Engines.Engine("ada").Completions.CreateCompletionAsync( new CompletionRequestV1() { prompt = "hello", max_tokens = 8 } ); while (!resTask.IsCompleted) { yield return(new WaitForEndOfFrame()); } ApiResult <CompletionV1> res = resTask.Result; Assert.IsNotNull(res); Assert.That(res.IsSuccess); Assert.IsNotNull(res.Result); }
// Issue: https://github.com/hexthedev/OpenAi-Api-Unity/issues/10 // For some reason the completer is logging twice public IEnumerator Issue010_CompleterLoggingTwice() { TestManager test = TestManager.Instance; OpenAiApiV1 api = test.CleanAndProvideApi(); OpenAiCompleterV1 comp = OpenAiCompleterV1.Instance; yield return(new WaitForEndOfFrame()); int count = 0; string res = null; HttpResponseMessage err = null; yield return(OpenAiCompleterV1.Instance.Complete( "test", extractRes, extractErr )); int count2 = count; string res2 = res; HttpResponseMessage err2 = err; Assert.IsNotNull(res); Assert.IsNull(err); Assert.That(count == 1); void extractRes(string r) { res = r; count++; } void extractErr(HttpResponseMessage e) { err = e; count++; } }
public IEnumerator CompletionsCreateCoroutine_EventStream() { TestManager test = TestManager.Instance; OpenAiApiV1 api = test.CleanAndProvideApi(); ApiResult <CompletionV1> result = null; List <CompletionV1> partials = new List <CompletionV1>(); bool isComplete = false; CompletionRequestV1 req = new CompletionRequestV1() { prompt = "hello", n = 8 }; yield return(api.Engines.Engine("ada").Completions.CreateCompletionCoroutine_EventStream( test, req, (r) => result = r, (i, l) => partials.Add(l), () => isComplete = true )); float timer = 10f; while (!isComplete) { timer -= Time.deltaTime; yield return(new WaitForEndOfFrame()); } Assert.That(isComplete); Assert.IsNotNull(result); Assert.That(result.IsSuccess); Assert.IsNotEmpty(partials); }
public IEnumerator Completions_TestAllRequestParamsArray() { TestManager test = TestManager.Instance; OpenAiApiV1 api = test.CleanAndProvideApi(); ApiResult <CompletionV1> result = null; CompletionRequestV1 req = new CompletionRequestV1() { prompt = new string[] { "prompt1", "prompt2" }, best_of = 1, echo = false, frequency_penalty = 0, presence_penalty = 0, logit_bias = new Dictionary <string, int>() { { "123", -100 }, { "111", 100 } }, stop = new string[] { "stop1", "stop2" }, logprobs = 0, stream = false, max_tokens = 8, n = 1, temperature = 0, top_p = 1 }; yield return(api.Engines.Engine("ada").Completions.CreateCompletionCoroutine(test, req, (r) => result = r)); Assert.IsNotNull(result); Assert.That(result.IsSuccess); Assert.IsNotNull(result.Result); Assert.IsNotEmpty(result.Result.choices); Assert.That(result.Result.choices.Length > 0); }