Help with HTTPService

Hello Everyone, I’ve been looking for tutorials on how I can interact with websites but I don’t really understand anything.

How can I interact with a website using HTTPService, then return a specific text from that web?

For example, I wanted to use Google’s calculator


then when I press a number on the game (1 for example), it sends a request to the calculator to type 1, then I choose an operation (still in the game), then it sends it also to the calculator site, so I already have 1+ and I need one more number so I type 4 (in the game) then it sends it to the calculator again, then I press equal, so it sends it to the website again, then ofcourse it would output 5, then the game receives 5. But the problem is, I don’t know how to interact with websites (click buttons) as I am new to HTTPService. So how can I interact with websites and then get the output from it? Thank you in advance.

1 Like

It looks like the Google calculator has no API, so you can’t interact with it with code. Also, this is not how HTTP requests work, you do not tell the website to click on a button, you tell the website what buttons you clicked and wait for the website to give a response.

Not possible in default lua.

You could use web scraping. Turn it into an api to do the calculations and return it. I could write a code sample if u want just not on my pc rn

Oh, well I’m not really going to use the calculator.

I want to use hugging face gpt-neo, is it possible?

I need it to take the input from the player, then type it in the text bar (the one with “Once upon a time,” in it) then, run the compute button, and get the json output

I’m not really going to use google’s calculator but is it possible for hugging face? EleutherAI/gpt-neo-1.3B · Hugging Face

If it has an api then yes u can use it.

If you’re trying to reference the html elements itself then u’ll need webscraping.

I think it has an api but I don’t really know how can I do it since I’m new to https, can you explain more how I can do it?

Do webscraping or using it’s api?

I want to do it with the api

This text will be hidden

I cant help rn since im not on my pc.

I’d recommend u check the docs.

oh, okay. I’ve already read it but I couldn’t understand anything. I guess I’ll just have to read it again

This is possible with HttpService:PostAsync()

Using Chrome’s DevTools, I inspected the network request made when you press “Compute”. The URL is https://api-inference.huggingface.co/models/EleutherAI/gpt-neo-1.3B and the POST body is {"inputs": "Once upon a time,"}, with “Once upon a time” being your input for the AI.

Then, use HttpService:PostAsync to POST to the endpoint.

(Make sure you’re doing this on the server)

local HttpService = game:GetService("HttpService")

local data = { ["inputs"] = "Once upon a time," }
local json = HttpService:JSONEncode(data)

local response = HttpService:PostAsync("https://api-inference.huggingface.co/models/EleutherAI/gpt-neo-1.3B", json)
local decoded = HttpService:JSONDecode(response)

print(decoded[1].generated_text)
3 Likes

Thank you! I got the code working now. I really appreciate it.

1 Like