Skip to content

Commit a93d40b

Browse files
author
CodeWithRodi
committed
[BUG SOLVED]: Formatted responses (Code - Lists).
1 parent 86ea987 commit a93d40b

File tree

7 files changed

+36
-22
lines changed

7 files changed

+36
-22
lines changed

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

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

27-
import React, { useEffect } from 'react';
27+
import React from 'react';
2828
import { BsRobot } from 'react-icons/bs';
2929
import { TbBrandRedhat } from 'react-icons/tb';
3030
import { With } from '../../../Utilities/Runtime';
@@ -53,12 +53,16 @@ const RenderResponse = ({ Content, Discipline }) => (
5353
wrapLines={true}
5454
codeBlock={true}
5555
text={CodeContent.join('\n')} />
56-
), Code.split('\n')))}
56+
), Code.split('\n').slice(0, -1)))}
5757
<p>{FinalContent}</p>
5858
</React.Fragment>
5959
), Content.split('```')))
6060
) : (
61-
<p>{Content}</p>
61+
(Content.includes('\n') ? (
62+
Content.split('\n').map((Part) => <p>{Part}</p>)
63+
) : (
64+
<p>{Content}</p>
65+
))
6266
))
6367
) : (
6468
<WaitingResponse />

Client/src/Services/Chat/Context.jsx

+9-5
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,14 @@ export const ChatProvider = ({ children }) => {
8080

8181
const HandleChatResponseSelect = (ListID) => {
8282
const Buffer = [];
83-
Service.StoredChatResponses()[ListID].forEach(({ Prompt, Response, ID }) =>
84-
(Buffer.push({ Discipline: 'Client', Answer: Prompt, ID }, { Discipline: 'Server', Answer: Response, ID })));
85-
SetStreamedResponses({});
86-
SetAPIResponses(Buffer);
83+
try{
84+
Service.StoredChatResponses()[ListID].forEach(({ Prompt, Response, ID }) =>
85+
(Buffer.push({ Discipline: 'Client', Answer: Prompt, ID }, { Discipline: 'Server', Answer: Response, ID })));
86+
SetStreamedResponses({});
87+
SetAPIResponses(Buffer);
88+
}catch(PersistChatError){
89+
Service.ClearChatResponses();
90+
}
8791
};
8892

8993
const MountModifiedChatResponseList = (ID) => {
@@ -126,7 +130,7 @@ export const ChatProvider = ({ children }) => {
126130
SetStreamedResponses((StreamedResponses) => {
127131
const Buffer = {
128132
...StreamedResponses,
129-
[RequestedPrompt]: { Response: StreamedResponses[RequestedPrompt].Response += Answer, ID } };
133+
[RequestedPrompt]: { Response: StreamedResponses[RequestedPrompt].Response += Answer + '\n', ID } };
130134
Service.StoreChatResponse({
131135
...ServerQuery,
132136
Prompt: RequestedPrompt,

Client/src/Services/Chat/Service.js

+4
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ export const RetrieveChatResponseDateData = (DateInstance = new Date()) => {
9393
];
9494
};
9595

96+
export const ClearChatResponses = () => {
97+
localStorage.clear(LocalStorageIdentifier.Historial);
98+
};
99+
96100
export const StoreChatResponse = (Response, Index = undefined) => {
97101
const [ Identifier, CreatedAt ] = RetrieveChatResponseDateData();
98102
const CurrentStoredResponses = StoredChatResponses() || {};

Server/Requirements.txt

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

Server/Tools/GPT/GPTHandler.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import json, sys, g4f
22

3+
g4f.version_check = False
4+
35
AvailableProviders = json.loads(sys.argv[1])
46

57
try:
68
Query = json.loads(sys.argv[2])
79
except:
810
Query = {}
911

10-
def FormatQueryMessages(Messages: tuple, Provider) -> tuple:
12+
def FormatQueryMessages(Messages: tuple) -> tuple:
1113
BASE_MESSAGES = [{
12-
'role': 'user' if Provider == 'ChatBase' else 'system',
14+
'role': 'system',
1315
'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.'
1416
}]
1517
return BASE_MESSAGES + [ {
16-
'role': 'user' if Provider == 'ChatBase' else Message.get('Role', 'user').lower(),
18+
'role': Message.get('Role', 'user').lower(),
1719
'content': Message.get('Content') } for Message in Messages ]
1820

1921
def GetProviderData(Provider) -> dict:
@@ -52,20 +54,21 @@ def MainFN() -> None:
5254
elif sys.argv[3] == 'API' or sys.argv[3] == 'WS':
5355
Model = Query['Model']
5456
Provider = None if Query['Provider'] == 'Automatic' else ImportProvider(Query['Provider'])
55-
Messages = FormatQueryMessages(Query['Messages'], Query['Provider'])
57+
Messages = FormatQueryMessages(Query['Messages'])
5658
if sys.argv[3] == 'API':
57-
print(g4f.ChatCompletion.create(
59+
Response = g4f.ChatCompletion.create(
5860
model=Model,
5961
provider=Provider,
60-
messages=Messages))
62+
messages=Messages)
63+
print(Response.join('\n'))
6164
else:
6265
StreamedResponse = g4f.ChatCompletion.create(
6366
model=Model,
6467
messages=Messages,
6568
provider=Provider,
6669
stream=True)
6770
for Message in StreamedResponse:
68-
print(Message)
71+
print(Message, end='', flush=True)
6972
except Exception as GPTException:
7073
print(GPTException)
7174

Server/Tools/GPT/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ const HandlePyShellResponse = (Options, PyShell) => new Promise((Resolve, Reject
5050
Reject(FormattedException);
5151
});
5252
PyShell.on('message', (Message) => {
53-
(Options?.CommunicationMode === 'WS') ? (Options?.Callback?.(Message)) : (Resolve(Message));
53+
if(Options?.CommunicationMode === 'WS')
54+
Options?.Callback?.(Message);
55+
else
56+
Resolve(Message);
5457
});
5558
PyShell.on('close', () => {
5659
Resolve();

Server/Utilities/Runtime.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,8 @@ exports.AvailableProviders = {
3434
'Automatic',
3535
],
3636
'API': [
37-
'GptGo',
38-
'ChatgptAi',
39-
'ChatBase',
40-
'DeepAi',
37+
'Acytoo',
4138
'Bing',
42-
'Vitalentum',
4339
'You',
4440
'Automatic'
4541
]

0 commit comments

Comments
 (0)