Skip to content

Commit

Permalink
ResultChat class was modified
Browse files Browse the repository at this point in the history
  • Loading branch information
SermetPekin committed Aug 21, 2024
1 parent 324047f commit 10cf55c
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 14 deletions.
19 changes: 11 additions & 8 deletions evdschat/core/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
from evdschat.model.chatters import ModelAbstract, OpenAI
from ..common.github_actions import PytestTesting
from typing import TypeVar, Tuple, Union
from .result import ResultChat

Result = TypeVar("Result")
# Result = TypeVar("Result")
Notes = TypeVar("Notes")


Expand All @@ -33,7 +34,7 @@ def chat(
debug=False,
test=False,
force=False,
) -> Union[Tuple[Result, Notes], None]:
) -> Union[Tuple[ResultChat, Notes], None]:
"""
Function to process the chat prompt and return the result.
Expand All @@ -53,7 +54,7 @@ def chat(
if isinstance(res, type(None)):
raise GotNoneFromGetter()
if isinstance(res, str):
return res,""
return res, ""
if isinstance(res, bool):
raise ValueError(
"""
Expand All @@ -68,7 +69,7 @@ def chat(
Please try again later or check documentation for
new API URLs"""
)
if not isinstance(res , tuple ) or len(res ) != 2 :
if not isinstance(res, tuple) or len(res) != 2:
raise GotUndefinedResult()
result, notes = res
return result, notes
Expand All @@ -92,10 +93,12 @@ def chat_console():
result, notes = chat(prompt=args.prompt, debug=args.debug, test=args.test)
print(result)
print(notes)
def correct(x:str):
if x.endswith('.xlsx') : return x
return f'{x}.xlsx'


def correct(x: str):
if x.endswith(".xlsx"):
return x
return f"{x}.xlsx"

result.to_excel(f"{correct(args.file_name)}")


Expand Down
52 changes: 52 additions & 0 deletions evdschat/core/result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from dataclasses import dataclass
import pandas as pd

from evdspy.EVDSlocal.index_requests.get_series_indexes_exp import Result

from enum import Enum
from typing import Any

class Status(Enum):
success= 1
failed= 0
unknown= 2


@dataclass
class ResultChat(Result):
status: Status = Status.unknown
reason: str = ""

def __str__(self):
content = super().__str__()
return f"""
! get_series_exp function returns instance of this class
<ResultChat>
status : {self.status.name} => Indicates the status of the result
reason : {self.reason} => Provides additional context if the status is not success
data : pd.DataFrame => Contains data [same as what get_series function returns]
metadata : pd.DataFrame => Contains metadata if available
write : Callable => Creates an Excel file with data and metadata in two sheets
to_excel : Callable => Same as write to meet pandas to_excel function
""" + content


def create_result(result: Any, status: Status = None, reason: str = "") -> ResultChat:
if status is None:
status = Status.unknown

if isinstance(result, Result):
return ResultChat(data=result.data, metadata=result.metadata, write=result.write, status=status, reason=reason)

if isinstance(result, pd.DataFrame):
r = Result(data=result, metadata=pd.DataFrame(), write=None) # Replace None with a suitable write function if available
return ResultChat(data=r.data, metadata=r.metadata, write=r.write, status=status, reason=reason)

if result is None:
r = Result(data=pd.DataFrame(), metadata=pd.DataFrame(), write=None) # Replace None with a suitable write function if available
return ResultChat(data=r.data, metadata=r.metadata, write=r.write, status=status, reason=reason)



__all__ = ["ResultChat"]
14 changes: 11 additions & 3 deletions evdschat/model/chatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
import os
from pathlib import Path

import pandas as pd

from evdschat.core.result import Result, ResultChat , create_result
from evdschat.core.result import Status




def get_myapi_url():
from dotenv import load_dotenv
Expand Down Expand Up @@ -101,11 +108,12 @@ def eval(self, kw: dict, permitted=None) -> Union[Tuple[Any, str], None]:
del kw["notes"]
try:
result = self.retrieve_fnc(kw["index"], **nkw)

return result, notes
res = create_result(result)
return res, notes
except Exception:
traceback.print_exc()
return None

return create_result(None, "Eval failed") , str("")

def decide_caller(self):
if self.test:
Expand Down
15 changes: 12 additions & 3 deletions evdschat/src/getter.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,34 @@ static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *use
return realsize;
}


const char *get_proxy_for_url(const char *url, const char *proxy_url)
{
if (proxy_url != NULL)
return proxy_url;

const char *https_proxy = getenv("HTTPS_PROXY");
const char *http_proxy = getenv("HTTP_PROXY");

if (strncmp(url, "https", 5) == 0 && https_proxy != NULL)

// Check for lowercase environment variables as well
if (https_proxy == NULL)
https_proxy = getenv("https_proxy");
if (http_proxy == NULL)
http_proxy = getenv("http_proxy");

if (strncmp(url, "https", 5) == 0)
{
return https_proxy;
}
else if (http_proxy != NULL)
else
{
return http_proxy;
}

return NULL;
}


char *post_request(const post_params *params)
{

Expand Down

0 comments on commit 10cf55c

Please sign in to comment.