Error BC30574: Option strict on disallows late binding. At line 15

I am trying to use chat GPT with API calls and get the following error. I do not have much experience with VB.Net or the invoke code activity so any help would be much appreciated

@Jacob_Orkis

Welcome to the forum
give a try at Line 14
Dim responseContent As JObject = …

Also start a try at Line 15 with
…(0)(“text”).toString

Making those changes I get a new error that says "option strict on disallows implicit conversion from Object to JObject. At line 14

can you share your xaml?

Since I am a new user it does not allow me to upload the xaml. the code is as follows:
Dim client As HttpClient = New HttpClient()
client.DefaultRequestHeaders.Add(“Authorization”, “Bearer ”)
client.DefaultRequestHeaders.Add(“Content-Type”, “application/json”)

    Dim requestBody As String = JsonConvert.SerializeObject(New With {
        Key .prompt = "What is a good taco recipe?",
        Key .max_tokens = 100
    })

    Dim response As HttpResponseMessage = client.PostAsync("https://chat.openai.com/chat", New StringContent(requestBody)).Result
    If response.IsSuccessStatusCode Then
        Dim responseContent As String = response.Content.ReadAsStringAsync().Result
        Dim responseObject As JObject = JsonConvert.DeserializeObject(Of Object)(responseContent)
        Dim answer As String = responseObject("choices")(0)("text").ToString
        Console.WriteLine("Answer: " & answer)
    Else
        Console.WriteLine("Request failed with status code: " & response.StatusCode.ToString())
    End If
    Console.ReadLine()

Additionally here are the imported namespaces:

Hi @Jacob_Orkis,

I don’t know if there is a specific reason for you to use invoke code activity, but if not, I would recommend you to use HTTP Request activity, which is a lot easier to work with.

Go to your manage packages and search under official for WebActivities package from UiPath. Add it to you process and then search for the activity.

Regarding the API, openAI has a free API to use their models, such as davinci-003, which is the one used by ChatGPT. I would suggest taking a look at the documentation, since the endpoints and body are a little different.

https://platform.openai.com/docs/api-reference/completions

Also, pay attention to max_token parameters, davinci-003 supports up to 4k tokens, I would recommend you to change it for something a little bigger.

Just to give you an ideia, your workflow could look like this:

1 Like

try the following:

 Dim responseObject As JObject = JsonConvert.DeserializeObject(Of JObject)(responseContent)

JsonConvert.DeserializeObject(Of -->J <–Object)

Also have a look here:

1 Like

Ok I will definitely look into that tutorial. The code change seems to have fixed the pervious error but there is a new one stating that the HTTP Client is ambiguous