OpenAi into Uipath


After the read CSV from excel, im not sure what is the next step. I want to use OpenAi to generate a response and input it into a word document where it recommends people compatible parts based on the excel file.

@2305002d

instead of open ai you have UiPath gen ai activities which you can use like generate text and you need to give prompt and substitute your excel values into the prompt so that the required text is generated

cheers

1 Like

hey bro if u dont mind, go give me the list of activities i need to use

@2305002d

for each row in datatable and then generate text inside it..then write to word doc inside theloop

cheers

will try thank you!!

1 Like

Read and Format CSV Content

After Read CSV, you’ll have a DataTable (e.g., dtParts).

You need to convert this DataTable to a string to send as part of your OpenAI prompt.

Use Output Data Table activity:

  • Input: dtParts

  • Output: csvText (String)


Construct the OpenAI Prompt

Use an Assign activity to create a full prompt.

prompt = "You are a parts compatibility expert. Based on the following parts list, recommend compatible replacement or supporting parts for each item. Return the results in a bullet list with clear explanations." & vbNewLine & csvText

Make sure you’re inserting the actual parts list (csvText) into the message.


Send the Prompt to OpenAI via HTTP Request

Your HTTP Request should be set up like this:

Method: POST

Endpoint:

https://api.openai.com/v1/chat/completions

Headers:

  • Authorization: Bearer YOUR_OPENAI_API_KEY

  • Content-Type: application/json

Body (JSON):

{ "model": "gpt-4", "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "<your prompt variable here>" } ], "temperature": 0.7 }

In the Body field, insert your prompt variable inside the user content.


Extract the Response

After the HTTP Request:

  • Store the response in a string variable (e.g., responseJson).

Use Deserialize JSON activity:

  • Input: responseJson

  • Output: jsonResponse (JObject)

Extract the content:

responseText = jsonResponse("choices")(0)("message")("content").ToString


Write to Word Document

Use the Word Application Scope + Add Text activity:

Word Application Scope:

  • File Path: "YourFilePath.docx"

Add Text:

  • Text: responseText

If worked then Mark it as SOLUTION

Happy Automation

they show me this (im still learning do be patient with me)


i have tried running, but they gave me this
(Deserialize JSON: Unexpected character encountered while parsing value: Y. Path ‘’, line 0, position 0.)

Create a string variable (e.g., jsonBody) with the full body:

jsonBody = "{ ""model"": ""gpt-4"", ""messages"": [ { ""role"": ""system"", ""content"": ""You are a helpful assistant."" }, { ""role"": ""user"", ""content"": """ & prompt & """ } ], ""temperature"": 0.7 }"

Make sure prompt includes your CSV data (as shown earlier)

In the HTTP Request activity

Method: POST

Endpoint: https://api.openai.com/v1/chat/completions

Headers:

Authorization: Bearer YOUR_API_KEY

Content-Type: application/json

Body: use the variable jsonBody

Ensure Body Format is set to application/json (not form-data or parameters).

In your HTTP Request activity:

Set the Response output to a variable like: responseJson (type: String)

Use Deserialize JSON on responseJson, not prompt:

JSON string → responseJson

Extract the actual response text from the OpenAI API:

responseText = jsonObj(“choices”)(0)(“message”)(“content”).ToString

will try, thank you!!!

1 Like

if you find needful mark it as solution

Happy Automation

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.