occ-ai / obs-urlsource

OBS plugin to fetch data from a URL or file, connect to an API or AI service, parse responses and display text, image or audio on scene
https://obsproject.com/forum/resources/url-api-source-fetch-live-data-and-display-it-on-screen.1756/
GNU General Public License v2.0
130 stars 18 forks source link

inja templating {{input}} not working #77

Closed saymrwulf closed 1 week ago

saymrwulf commented 4 months ago

local inference server running in LMStudio URLsource with http POST & 1) request body without templating { "messages": [{ "role": "user", "content": "hello"}]} --> works & returns expected response body 2) request body with improper templating like { "messages": [{ "role": "user", "content": "hello {input}"}]} --> works & returns response body with garbage content (as expected), which means there was no text replacement to begin with 3) request body with proper templating { "messages": [{ "role": "user", "content": "hello {{input}}"}]} --> {"error":"'messages' field is required"} which means the templating escaped and destroyed the json structure without leaving a json syntax error

Environments (same error in both environments): a) Apple Silicon, Sonoma, fresh OBS , LMStudio, URLsource b) Win11 x64, fresh OBS, LMStudio, URLsource

royshil commented 4 months ago

can i see the request builder screenshot? it might be formattign the JSON incorrectly resulting in an error from OpenAI specifically the problem is with newlines \n not injected properly

saymrwulf commented 4 months ago

several attempts: first a direct copy from the LMStudio LocalInferenceServer Model client example code but with inserted newlines by me, then a more minimal representation with correct indentations but without newline, then the most minimal version on one line, and lastly a version without templating just to show that the setup works in general.

Screenshot 2024-02-14 at 15 26 14 Screenshot 2024-02-14 at 15 27 48 Screenshot 2024-02-14 at 15 34 20 Screenshot 2024-02-14 at 15 36 46
royshil commented 4 months ago

@saymrwulf i think th problem is malformatted JSON body are you still stuck on this?

saymrwulf commented 4 months ago

still stuck on this. malformed json ? The 2nd pic is the one with the most simple request. still fails.

saymrwulf commented 4 months ago

could you post a json request that according to you should not fail ? One that contains the templating mechanism ?

royshil commented 4 months ago

@saymrwulf for example

image
{
    "model": "gpt-3.5-turbo",
    "messages": [
      {
        "role": "user",
        "content": "{{input}}"
      }
    ]
  }
saymrwulf commented 4 months ago

not working. As soon as I remove one pair of {} , the chat works, of course not as intended, because no templating/replacement has happened (as expected). The construct "{{input}}" however is flawed. Is there some extra installation/configuration required for inja to work ?

royshil commented 4 months ago

@saymrwulf i don't think there's dependency problem since inja is built from source inside the plugin. i suspect that {{input}} doesn't work simply because it doesn't have any input and the request never fires. in your latest examples you had "Agg to Empty" on what if you remove that?

saymrwulf commented 4 months ago

I removed "Agg to Empty". Same result. The file that is fed into URLencode does exist and it contains live data. The only thing I find a bit suspicious is that it contains a lot of empty lines. Other than that the setup looks normal.

royshil commented 4 months ago

@saymrwulf so if you hit "test" in the request builder - the body preview shows the content instead of {{input}}?

saymrwulf commented 4 months ago

no the body stays as it is with the line { "role": "user", "content": "{{input}}" } and all the rest as it was from the get go

saymrwulf commented 4 months ago

... and then the server does not like this whole string and thinks ..."{{ ... is some sort of escape mechanism that destroy the whole "messages" structure

royshil commented 4 months ago

@saymrwulf if the body doesn't replace {{input}} then it doesn't have input for the replacement can i see your latest request builder screen again? and the body text verbatim use "```" to paste the body text here so i can see exactky how its formatted

saymrwulf commented 4 months ago
Screenshot 2024-03-06 at 13 37 41
saymrwulf commented 4 months ago

this is the body: " { "messages": [ { "role": "system", "content": "Always answer in rhymes." }, { "role": "user", "content": "{{input}}" } ], "temperature": 0.7, "max_tokens": -1, "stream": false } "

royshil commented 4 months ago

@saymrwulf i think you should at any rate enable "Skip empty" and "Skip same" the template seems fine so i see no reason for inja to not replace the {{input}} except when it's empty try the "skip"s and see, please

saymrwulf commented 3 months ago

Problems are caused by other faults - has nothing to do with inja indeed. Observe weird OBS behavior stubbornly refusing to function according to the config settings. Constantly deviating between what you see and what you get. And if you violently force OBS to accept config changes (by deleting the source one wants to reconfigure and re-install it), OBS is always crashing now. (MacBook M3 128GB). (BTW: The skip-empty trick is basically a way to force OBS to come up with the correct error message which is, that it finds an emptyness only...)

royshil commented 1 week ago

closing for now