Closed niizam closed 5 months ago
I think I've figured out the issue here. The proxy is returning the response in a slightly different key order and potentially without any line formatting, which was throwing off the extension's response parsing logic.
I've implemented some more flexible response parsing in this beta update, can you test this out when you get the chance? GptApiTranslate-v1.1.4-beta.zip
I think I've figured out the issue here. The proxy is returning the response in a slightly different key order and potentially without any line formatting, which was throwing off the extension's response parsing logic.
I've implemented some more flexible response parsing in this beta update, can you test this out when you get the chance? GptApiTranslate-v1.1.4-beta.zip
Thank you!, it definitely works
@voidpenguin-28 I'm wondering if there's a plan to support Gemini AI, since they offer a free API. Here's an example of its usage.
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=$GOOGLE_API_KEY \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [
{"role":"user",
"parts":[{
"text": "Translate novel script to natural fluent EN. Preserve numbering. Use all JP input lines as context (previous lines). However, only return the translation for the line that starts with '99:'."}]},
{"role": "user",
"parts":[{
"text": "\n97: 村を去った日と同じだ。俺を乗せて来たのがタイムマシンであったかのように、岬の眺めはあの日と変わらない。\n\n98: 滲んだ汗をぬぐい、荷物を背負い直した俺は、もう間近に迫った目的地へと足の向きを変える。\n\n99: ガードレールに沿ってほんの30秒ほど。"}]},
],
"safetySettings": [
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "BLOCK_NONE"
},
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "BLOCK_NONE"
},
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_NONE"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "BLOCK_NONE"
}
],
"generationConfig": {
"temperature": 1.0,
"maxOutputTokens": 512,
"topP": 0.95,
"topK": 64
}
}'
Result
{
"candidates": [{
"content": {
"parts": [{
"text": "99: Along the guardrail for just about 30 seconds."
}],
"role": "model"
},
"finishReason": "STOP",
"index": 0,
"safetyRatings": [{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"probability": "NEGLIGIBLE"
},
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"probability": "NEGLIGIBLE"
},
{
"category": "HARM_CATEGORY_HARASSMENT",
"probability": "NEGLIGIBLE"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"probability": "NEGLIGIBLE"
}
]
}],
"usageMetadata": {
"promptTokenCount": 125,
"candidatesTokenCount": 15,
"totalTokenCount": 140
}
}
I just tested the API a bit, and its results aren't half bad. I'll add it to my list of tasks to work on, but it may be a bit of time before I take a look at it. I'll give an update in this thread if this gets implemented.
That's fine, take your time, and thanks for considering it. Looking forward to any updates on this.
Hi. I just updated the extension to v1.2.0, which will allow you to be able to integrate the Gemini API. https://github.com/voidpenguin-28/Textractor-ExtraExtensions/releases/tag/GptApiTranslate-v1.2.0
Rather than implementing the Gemini API directly in the extension itself, I've implemented a more flexible approach that should allow you to implement any API/endpoint you want.
v1.2 introduces 4 new config values which allows users to provide custom functionality for sending API requests and parsing API responses: CustomRequestTemplate, CustomResponseMsgRegex, CustomErrorMsgRegex, CustomHttpHeaders
More details on each config value can be found in the extension's documentation.
As for how to integrate the Gemini API with this, just simply add the following to your .ini config (fill in the Model & ApiKey), and you should be all set.
Url=https://generativelanguage.googleapis.com/v1beta/models/{1}:generateContent?key={0}
ApiKey=***GEMINI API KEY HERE***
Model=***DESIRED GEMINI MODEL HERE (ex: gemini-1.5-flash)***
CustomRequestTemplate={"systemInstruction":{"role":"user","parts":[{"text":"{1}"}]},"contents":[{"role":"user","parts":[{"text":"{2}"}]}],"safetySettings":[{"category":"HARM_CATEGORY_SEXUALLY_EXPLICIT","threshold":"BLOCK_NONE"},{"category":"HARM_CATEGORY_HATE_SPEECH","threshold":"BLOCK_NONE"},{"category":"HARM_CATEGORY_HARASSMENT","threshold":"BLOCK_NONE"},{"category":"HARM_CATEGORY_DANGEROUS_CONTENT","threshold":"BLOCK_NONE"}]}
CustomResponseMsgRegex="[Tt]ext":\\s{0,}"((?:\\\\"|[^"])*)"
CustomErrorMsgRegex=
CustomHttpHeaders=Content-Type: application/json
Hi. I just updated the extension to v1.2.0, which will allow you to be able to integrate the Gemini API. https://github.com/voidpenguin-28/Textractor-ExtraExtensions/releases/tag/GptApiTranslate-v1.2.0
Rather than implementing the Gemini API directly in the extension itself, I've implemented a more flexible approach that should allow you to implement any API/endpoint you want.
v1.2 introduces 4 new config values which allows users to provide custom functionality for sending API requests and parsing API responses: CustomRequestTemplate, CustomResponseMsgRegex, CustomErrorMsgRegex, CustomHttpHeaders
More details on each config value can be found in the extension's documentation.
As for how to integrate the Gemini API with this, just simply add the following to your .ini config (fill in the Model & ApiKey), and you should be all set.
Url=https://generativelanguage.googleapis.com/v1beta/models/{1}:generateContent?key={0} ApiKey=***GEMINI API KEY HERE*** Model=***DESIRED GEMINI MODEL HERE (ex: gemini-1.5-flash)*** CustomRequestTemplate={"systemInstruction":{"role":"user","parts":[{"text":"{1}"}]},"contents":[{"role":"user","parts":[{"text":"{2}"}]}],"safetySettings":[{"category":"HARM_CATEGORY_SEXUALLY_EXPLICIT","threshold":"BLOCK_NONE"},{"category":"HARM_CATEGORY_HATE_SPEECH","threshold":"BLOCK_NONE"},{"category":"HARM_CATEGORY_HARASSMENT","threshold":"BLOCK_NONE"},{"category":"HARM_CATEGORY_DANGEROUS_CONTENT","threshold":"BLOCK_NONE"}]} CustomResponseMsgRegex="[Tt]ext":\\s{0,}"((?:\\\\"|[^"])*)" CustomErrorMsgRegex= CustomHttpHeaders=Content-Type: application/json
You are the GOAT! Thank you for the update. I really appreciate you adding the ability to integrate custom APIs and makes it easy to support different APIs and is great for future-proofing the extension.
I'll test out the new version and try using the new config options. If I run into any issues or have any other feedback, I'll let you know in this thread.
Quick update here. A few issues were recently found with the custom api functionality, which now should be fixed.
The following 2 steps should fix this issue.
Url=https://generativelanguage.googleapis.com/v1beta/models/{1}:generateContent?key={0}
ApiKey=***GEMINI API KEY HERE***
Model=***DESIRED GEMINI MODEL HERE (ex: gemini-1.5-flash)***
CustomRequestTemplate={\"systemInstruction\":{\"role\":\"user\", \"parts\":[{\"text\":\"{1}\"}]}, \"contents\":[{\"role\":\"user\", \"parts\":[{\"text\":\"{2}\"}]}], \"safetySettings\":[{\"category\":\"HARM_CATEGORY_SEXUALLY_EXPLICIT\", \"threshold\":\"BLOCK_NONE\"}, {\"category\":\"HARM_CATEGORY_HATE_SPEECH\", \"threshold\":\"BLOCK_NONE\"}, {\"category\":\"HARM_CATEGORY_HARASSMENT\", \"threshold\":\"BLOCK_NONE\"}, {\"category\":\"HARM_CATEGORY_DANGEROUS_CONTENT\", \"threshold\":\"BLOCK_NONE\"}]}
CustomResponseMsgRegex=\"[Tt]ext\":\\s{0,}\"((?:\\\\\"|[^\"])*)\"
CustomErrorMsgRegex=
CustomHttpHeaders=Content-Type: application/json
To explain why this issue was happening. Textractor has its own ini formatting logic that it applies every time the app is opened or closed. I was not aware that part of this logic was to auto-strip out all double quotes that aren't escaped.
So Textractor was auto-removing the double quotes from the CustomRequestTemplate & CustomResponseMsgRegex config values, which broke the extension.
This issue should be resolved now.
I'm using this ChatGPT API Free Reverse Proxy as the API endpoint
here's
gpt-response-log.txt
Textractor ver 5.20 x86 Screenshot:
Edit: changing the order of extensions also didn't fix the issue