Skip to content

Commit 86ea987

Browse files
author
CodeWithRodi
committed
Model suppliers and updated models. G4F updated.
1 parent c579b5c commit 86ea987

File tree

7 files changed

+62
-80
lines changed

7 files changed

+62
-80
lines changed

Client/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "lovelace-client",
33
"private": false,
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"type": "module",
66
"author": {
77
"name": "CodeWithRodi",

Client/src/Components/Chat/RenderResponse/RenderResponse.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
2525
****/
2626

27-
import React from 'react';
27+
import React, { useEffect } from 'react';
2828
import { BsRobot } from 'react-icons/bs';
2929
import { TbBrandRedhat } from 'react-icons/tb';
3030
import { With } from '../../../Utilities/Runtime';

Client/src/Services/Chat/Service.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const LocalStorageIdentifier = {
3131
Historial: 'Lovelace::Service::History'
3232
};
3333

34-
export const RecommendedProviders = { WS: 'DeepAi', API: 'DeepAi' };
34+
export const RecommendedProviders = { WS: 'Automatic', API: 'Automatic' };
3535
export const StoredChatResponses = () => QuickLocalStorageRescue(LocalStorageIdentifier.Historial);
3636

3737
export const AvailableSettings = {
@@ -46,10 +46,7 @@ export const AvailableSettings = {
4646
],
4747
Models: [
4848
['GPT-3.5-Turbo (Recommended)', 'gpt-3.5-turbo'],
49-
['GPT-4 (Unstable)', 'gpt-4'],
50-
['Falcon-40b', 'falcon-40b'],
51-
['Falcon-7b', 'falcon-7b'],
52-
['Llama-13b', 'llama-13b']
49+
['GPT-4 (Unstable)', 'gpt-4']
5350
]
5451
};
5552

Server/Requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
g4f==0.0.2.3
1+
g4f==0.1.5.5

Server/Tools/GPT/GPTHandler.py

+42-56
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,73 @@
1-
# =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
2-
# Copyright (C) Rodolfo Herrera Hernandez. All rights reserved.
3-
# Licensed under the MIT license. See LICENSE file in the project root
4-
# for full license information.
5-
#
6-
# =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
7-
#
8-
# In the vast universe of knowledge, the Open Source philosophy
9-
# shines like a radiant star. In this vein, Lovelace emerges
10-
# as an autonomous alternative to ChatGPT, based on
11-
# open source and self-hosting capabilities.
12-
#
13-
# Written in JavaScript, interacting with the <g4f> library written
14-
# in Python, allows communication with ChatGPT through the use
15-
# of different services that facilitate its use by the public.
16-
#
17-
# For related information - https://github.com/CodeWithRodi/Lovelace/
18-
# See also - https://github.com/xtekky/gpt4free
19-
#
20-
# :: https://lovelace.codewithrodi.com/
21-
# :: https://lovelace-backend.codewithrodi.com/
22-
# :: https://lovelace-docs.codewithrodi.com/
23-
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
24-
251
import json, sys, g4f
262

273
AvailableProviders = json.loads(sys.argv[1])
284

29-
# ! Is this the best way of do it?
305
try:
316
Query = json.loads(sys.argv[2])
327
except:
338
Query = {}
349

35-
BASE_MESSAGES = [{
36-
'role': 'system',
37-
'content': 'You are Ada Lovelace, a coding software developed to provide free access to OpenAI models. Your Github repository is "https://github.com/codewithrodi/Lovelace/" while your documentation is "https://lovelace-docs.codewithrodi.com/". Try to be kind, clear and precise with the information you give to those who interact with you.'
38-
}]
39-
40-
def FormatQueryMessages(Messages: tuple) -> tuple:
10+
def FormatQueryMessages(Messages: tuple, Provider) -> tuple:
11+
BASE_MESSAGES = [{
12+
'role': 'user' if Provider == 'ChatBase' else 'system',
13+
'content': 'You are Ada Lovelace, a coding software developed to provide free access to OpenAI models. Your Github repository is "https://github.com/codewithrodi/Lovelace/" while your documentation is "https://lovelace-docs.codewithrodi.com/". Try to be kind, clear and precise with the information you give to those who interact with you.'
14+
}]
4115
return BASE_MESSAGES + [ {
42-
'role': Message['Role'].lower(),
43-
'content': Message['Content'] } for Message in Messages ]
16+
'role': 'user' if Provider == 'ChatBase' else Message.get('Role', 'user').lower(),
17+
'content': Message.get('Content') } for Message in Messages ]
4418

4519
def GetProviderData(Provider) -> dict:
4620
ImportedProvider = ImportProvider(Provider)
21+
if(ImportedProvider is None):
22+
return {
23+
'Name': 'Automatic',
24+
'Website': 'https://github.com/codewithrodi/Lovelace/',
25+
'Models': ['gpt-3.5-turbo', 'gpt-4']
26+
}
4727
Models = []
4828
if(ImportedProvider.supports_gpt_35_turbo):
4929
Models.append('gpt-3.5-turbo')
5030
if(ImportedProvider.supports_gpt_4):
5131
Models.append('gpt-4')
52-
if(Provider == 'H2o'):
53-
Models.extend(['falcon-40b', 'falcon-7b', 'llama-13b'])
5432
return {
5533
'Name': Provider,
5634
'Website': ImportedProvider.url,
5735
'Models': Models
5836
}
5937

6038
def ImportProvider(ProviderName: str):
39+
if(ProviderName == 'Automatic'):
40+
return None
6141
return eval('g4f.Provider.' + ProviderName)
6242

6343
def MainFN() -> None:
64-
if sys.argv[3] == 'PROVIDERS':
65-
print(json.dumps({
66-
'Providers': {
67-
'WS': [GetProviderData(Provider) for Provider in AvailableProviders['WS']],
68-
'API': [GetProviderData(Provider) for Provider in AvailableProviders['API']]
69-
}
70-
}))
71-
elif sys.argv[3] == 'API':
72-
print(g4f.ChatCompletion.create(
73-
model=Query['Model'],
74-
provider=ImportProvider(Query['Provider']),
75-
messages=FormatQueryMessages(Query['Messages'])))
76-
else:
77-
# ! STREAMED RESPONSE (sys.argv[3] == 'WS')
78-
StreamedResponse = g4f.ChatCompletion.create(
79-
model=Query['Model'],
80-
messages=FormatQueryMessages(Query['Messages']),
81-
provider=ImportProvider(Query['Provider']),
82-
stream=True)
83-
for Message in StreamedResponse:
84-
print(Message)
44+
try:
45+
if sys.argv[3] == 'PROVIDERS':
46+
print(json.dumps({
47+
'Providers': {
48+
'WS': [GetProviderData(Provider) for Provider in AvailableProviders['WS']],
49+
'API': [GetProviderData(Provider) for Provider in AvailableProviders['API']]
50+
}
51+
}))
52+
elif sys.argv[3] == 'API' or sys.argv[3] == 'WS':
53+
Model = Query['Model']
54+
Provider = None if Query['Provider'] == 'Automatic' else ImportProvider(Query['Provider'])
55+
Messages = FormatQueryMessages(Query['Messages'], Query['Provider'])
56+
if sys.argv[3] == 'API':
57+
print(g4f.ChatCompletion.create(
58+
model=Model,
59+
provider=Provider,
60+
messages=Messages))
61+
else:
62+
StreamedResponse = g4f.ChatCompletion.create(
63+
model=Model,
64+
messages=Messages,
65+
provider=Provider,
66+
stream=True)
67+
for Message in StreamedResponse:
68+
print(Message)
69+
except Exception as GPTException:
70+
print(GPTException)
8571

8672
if __name__ == '__main__':
8773
MainFN()

Server/Utilities/Runtime.js

+14-15
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,31 @@
2626

2727
exports.AvailableProviders = {
2828
'WS': [
29-
'DeepAi',
30-
'GetGpt',
31-
'H2o'
29+
'Bing',
30+
'ChatBase',
31+
'GptGo',
32+
'Vitalentum',
33+
'Ylokh',
34+
'Automatic',
3235
],
3336
'API': [
34-
'Acytoo',
35-
'Aichat',
36-
'Ails',
37+
'GptGo',
3738
'ChatgptAi',
38-
'Vercel',
39-
'H2o',
40-
'Wewordle',
41-
'You',
42-
'Yqcloud',
39+
'ChatBase',
4340
'DeepAi',
44-
'DfeHub',
45-
'GetGpt'
41+
'Bing',
42+
'Vitalentum',
43+
'You',
44+
'Automatic'
4645
]
4746
};
4847
exports.AvailableRoles = ['user', 'assistant', 'system'];
49-
exports.AvailableModels = ['gpt-3.5-turbo', 'gpt-4', 'falcon-40b', 'falcon-7b', 'llama-13b'];
48+
exports.AvailableModels = ['gpt-3.5-turbo', 'gpt-4'];
5049

5150
exports.DefaultChatParameters = {
5251
Model: 'gpt-3.5-turbo',
5352
Role: 'user',
54-
Provider: 'DeepAi'
53+
Provider: 'Automatic'
5554
};
5655

5756
exports.RuntimeError = class extends Error{

Server/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "lovelace-server",
33
"private": false,
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"author": {
66
"name": "CodeWithRodi",
77
"email": "[email protected]",

0 commit comments

Comments
 (0)