mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-11-19 03:25:32 +00:00
commit
0e700a5a95
@ -105,6 +105,22 @@ class Api:
|
|||||||
|
|
||||||
logger.info(f'model: {model}, stream: {stream}, request: {messages[-1]["content"]}')
|
logger.info(f'model: {model}, stream: {stream}, request: {messages[-1]["content"]}')
|
||||||
|
|
||||||
|
config = None
|
||||||
|
proxy = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
config = json.load(open("config.json","r",encoding="utf-8"))
|
||||||
|
proxy = config["proxy"]
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if proxy != None:
|
||||||
|
response = self.engine.ChatCompletion.create(model=model,
|
||||||
|
stream=stream, messages=messages,
|
||||||
|
ignored=self.list_ignored_providers,
|
||||||
|
proxy=proxy)
|
||||||
|
else:
|
||||||
response = self.engine.ChatCompletion.create(model=model,
|
response = self.engine.ChatCompletion.create(model=model,
|
||||||
stream=stream, messages=messages,
|
stream=stream, messages=messages,
|
||||||
ignored=self.list_ignored_providers)
|
ignored=self.list_ignored_providers)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import g4f
|
import g4f
|
||||||
|
import json
|
||||||
|
|
||||||
from flask import request
|
from flask import request
|
||||||
from .internet import search
|
from .internet import search
|
||||||
@ -43,6 +44,15 @@ class Backend_Api:
|
|||||||
}
|
}
|
||||||
|
|
||||||
def _conversation(self):
|
def _conversation(self):
|
||||||
|
config = None
|
||||||
|
proxy = None
|
||||||
|
try:
|
||||||
|
config = json.load(open("config.json","r",encoding="utf-8"))
|
||||||
|
proxy = config["proxy"]
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
jailbreak = request.json['jailbreak']
|
jailbreak = request.json['jailbreak']
|
||||||
internet_access = request.json['meta']['content']['internet_access']
|
internet_access = request.json['meta']['content']['internet_access']
|
||||||
@ -54,6 +64,17 @@ class Backend_Api:
|
|||||||
messages = special_instructions[jailbreak] + conversation + search(internet_access, prompt) + [prompt]
|
messages = special_instructions[jailbreak] + conversation + search(internet_access, prompt) + [prompt]
|
||||||
|
|
||||||
def stream():
|
def stream():
|
||||||
|
if proxy != None:
|
||||||
|
yield from g4f.ChatCompletion.create(
|
||||||
|
model=model,
|
||||||
|
provider=get_provider(provider),
|
||||||
|
messages=messages,
|
||||||
|
stream=True,
|
||||||
|
proxy=proxy
|
||||||
|
) if provider else g4f.ChatCompletion.create(
|
||||||
|
model=model, messages=messages, stream=True, proxy=proxy
|
||||||
|
)
|
||||||
|
else:
|
||||||
yield from g4f.ChatCompletion.create(
|
yield from g4f.ChatCompletion.create(
|
||||||
model=model,
|
model=model,
|
||||||
provider=get_provider(provider),
|
provider=get_provider(provider),
|
||||||
|
Loading…
Reference in New Issue
Block a user