class FakeMessage:
def __init__(self, txt):
self.content = txt
class FakeChoice:
def __init__(self, txt):
self.message = FakeMessage(txt)
class FakeResponse:
def __init__(self, txt):
self.choices = [FakeChoice(txt)]
class FakeCompletions:
def create(self, **kwargs):
return FakeResponse("Reponse du LLM")
class FakeChat:
def __init__(self):
self.completions = FakeCompletions()
class FakeClient:
def __init__(self):
self.chat = FakeChat()
llm = ClientLLM("Tu es un assistant.", client=FakeClient())
r = llm.envoyer("Bonjour")
assert isinstance(r, str), f"envoyer() doit retourner un string, pas {type(r)}"
assert r == "Reponse du LLM"
class FakeMessage:
def __init__(self):
self.content = "OK"
class FakeChoice:
def __init__(self):
self.message = FakeMessage()
class FakeResponse:
def __init__(self):
self.choices = [FakeChoice()]
class FakeCompletions:
def create(self, **kwargs):
msgs = kwargs.get("messages", [])
assert msgs[0]["role"] == "system", "Le premier message doit etre le system prompt"
assert msgs[0]["content"] == "Tu es un expert Python.", f"System prompt incorrect: {msgs[0]['content']}"
return FakeResponse()
class FakeChat:
def __init__(self):
self.completions = FakeCompletions()
class FakeClient:
def __init__(self):
self.chat = FakeChat()
llm = ClientLLM("Tu es un expert Python.", client=FakeClient())
llm.envoyer("Test")
class FakeMessage:
def __init__(self):
self.content = "OK"
class FakeChoice:
def __init__(self):
self.message = FakeMessage()
class FakeResponse:
def __init__(self):
self.choices = [FakeChoice()]
class FakeCompletions:
def create(self, **kwargs):
assert kwargs.get("model") == "gpt-4o", f"Modele attendu gpt-4o, obtenu {kwargs.get('model')}"
return FakeResponse()
class FakeChat:
def __init__(self):
self.completions = FakeCompletions()
class FakeClient:
def __init__(self):
self.chat = FakeChat()
llm = ClientLLM("Sys", model="gpt-4o", client=FakeClient())
llm.envoyer("Test")
class FakeMessage:
def __init__(self):
self.content = "OK"
class FakeChoice:
def __init__(self):
self.message = FakeMessage()
class FakeResponse:
def __init__(self):
self.choices = [FakeChoice()]
class FakeCompletions:
def create(self, **kwargs):
assert kwargs.get("model") == "gpt-4o", f"Apres changer_model, le modele doit etre gpt-4o, pas {kwargs.get('model')}"
return FakeResponse()
class FakeChat:
def __init__(self):
self.completions = FakeCompletions()
class FakeClient:
def __init__(self):
self.chat = FakeChat()
llm = ClientLLM("Sys", model="gpt-4o-mini", client=FakeClient())
llm.changer_model("gpt-4o")
llm.envoyer("Test")
+ 0 tests cachés