From 16c755257b345e78bfefac2a513f744339d04013 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Sat, 30 Sep 2023 15:37:30 -0700 Subject: [PATCH] add support for custom hf prompt templates --- litellm/__pycache__/main.cpython-311.pyc | Bin 52139 -> 52158 bytes litellm/__pycache__/utils.cpython-311.pyc | Bin 136629 -> 137059 bytes litellm/llms/prompt_templates/factory.py | 122 ++++++++++++++++++---- litellm/tests/test_hf_prompt_templates.py | 27 +++-- litellm/tests/test_streaming.py | 106 ++++++++++--------- pyproject.toml | 2 +- 6 files changed, 172 insertions(+), 85 deletions(-) diff --git a/litellm/__pycache__/main.cpython-311.pyc b/litellm/__pycache__/main.cpython-311.pyc index 61a2e4b71bfad0a5aa50d74b8dee28ce82d71601..9f0a8d2cecaa0747921fc2b41286a5c0e7baf816 100644 GIT binary patch delta 880 zcmXAkZAep57=X`v?{w2`ZgabLGdFFb`GMxgEH#^Qx82Y`m1coN$xJISBts)h5y4D@ z(zt{uLK;Mc8N?e|(AR!Qh=HL&VLu9sLL$6VNs1ZWdptkR^SmGDyyr{|u`h>M<6WaM zmMAOljH9t>+{nW^#_@|Q@<@_rw@n```Q7Ck4APY|vKVqQ@ zxxF5MDXG#s3sn+VhOi;cluf`mwv{h4kd1Y|CV=zOtUp~_-!RhYXq}U~Jtfkhw*f{Z zccBaK1!}fID{dYSYvCHMoD2Y5!ot&yPQA<%Ge6jRwWF^?YPgu9sd!giD~)zLq_Y>a zxYRQSNgSEZspNzpN9I_+UFCdY#vu(^U_l9_v0leMj=awmQ`OR78BxCLINTfDUpRAUCTZIIb8#%rdm4D4XR%OIS zZ;I^Jbd-|F9`z)Nlv+9s?4}_=qmU5iFILkbQL7O|gF^jQK{Qwd(Zz;Dmp_I!RHTb} zRQ5ZBG)0b((1Eh8xuGhDK))TT-sv;Zrkb*R%ENgg{YB_#g0PEbj+p{cRDxWr5G-Ot z!DOotEKpdWxR3T58XcG<=kQxt#pU5X9dLN= zHlqhWwoQ&j!&BrR-(+AOA3Vtd_=+E<9s>Np-e&{R5Jvv>sIE&iL##~H{i8lkW@#8r zOjcP-RY%M=IfiO1vDsxkRRf8)%SNhk#9)z4RLw-Emn~G|iP0iksq)0a%XX>`Vt2|3 zRGq}a$u80CRi-BqWpXl2?;z1uIh`tf)7HzvT83fPiL!-R!svQM@x=9w5LZw;-QIX&SK@r6VDn6lV z{qeyfS{1E=D2P(MrL`Yw_rniS5KTTx{SZXOis-~AYJBWY_hZhvckZ1#v-i)?8)vBN zn#*M;#@DqcxNiPsR{-9jJ1`%{~*pxiU8A5X^L2&7S}Z2 zrqGK1IZ1%q+QOE{(5m@U2u1Bt>IR(09dkzon2f8_8v(Xxk26tm<=S)mDz`t?4kc%5 zCtG}4dnQV)dqwS1EClDYNK+X5vK`}$;pMA~A{@cr>$3oRaNdS>)zNPO;t3X{nx51% zX<9*=#z>iKV(-o&`Of~{{cl23hvk|c_3ke1;=vGp?7RjCB=Rt}(68hq@|0$RCZC7u zmRLxhf*Is3_70Ke-Ax?=EeK_X7sRN!QHZOxCP!p7Wb$QWns>jlrCnzHI*^W-eA~RB z&g7?v5-`b{tGD_|QRb%?{hEB#Z`|Q?GBd&4{q9q$O#X-W*s9~zB;Y>L%SP)ekxwKU(lMGo# z^hK$$xq5r0!heRocxqbWMIEUG=h8-%KSWLyMvlel__&B44}D~QX>d|U&>8(=}Ml_Xfrs<>7Yub+jpo)%;J qcw$VRz|)h7)yJY-`JKjYRulz6_)3hWNQq$U3@{rnX~RR0T7>_!$`;}P diff --git a/litellm/__pycache__/utils.cpython-311.pyc b/litellm/__pycache__/utils.cpython-311.pyc index 338c3b089645d248ad6f355d849ed2895e4a4341..d3a54a2d4ce6f9c1df91226ee7d4874596cac59a 100644 GIT binary patch delta 837 zcmZutYeA(D`wm%XwZ7=k<9bUNlGOFX(iU zf?V@TOglZE!+M_{{f%s5YR!CW0)1=5J9N-%FNQ?5Yc=_s5Wol>y@&x(avh*;%_x`2 zQhL@b4}#Qu2}e++#A2zS1#P0rm8OJZ$@aBbz)orp$MxJ)Q!$^}X}<9U52 z96$n z(npdr8tnC!WBP}N>0v|0xKK{Zui_c@QoJ8~P)t>RxZtE8eyoIpa(ZP|q(Bk{dy#_8 zlL0&5(I=n5a==es!y810Vp1O(&0*v07So_HD`?E(Kd&Q-X}749t=~QulJO?^q3v

^0<93xFj)k&kv5YUFf6kf#Gp71XS`@pKu1K;hxWk2hP#iFF1_`p7RwO7@BzP ocdXT5z&FB*RG7lECH7uFuT(v~5osWak!F;ds8D**&BB}LLQA1YA*@h2 zL?&KYXsw*to355C`V(zBj6|ABfn`6kKxtr9@0T|Py%*>CInUv|oc9iGe~;F1U9S(7 z#0z#sRWCI(82Swu?q;*AS~exbQLr0dkxX+vcrB~#ZgSs*7l*0&7Di>2eSs<*s1w9N z(+<(dCC6=?gRI12sNfEqvTVPqgks3jiz<}S**y1Ve8oa*~wA{WOGOz_rwSOensQGr;hAHY`1A3(+mZ&SzBvMLLi2Vp@x zWeuVf+o^RB{VV+pI_*LttkmT~3T)(a!O5E*pbgBWC950e*gU2?g#g>l^vScflp95z zmP>|7W7LE(B_P#Mu^ZEj&T35xG5U>wh=4> z7kTO{[INST] Be a good bot [/INST] [INST] Hello world [/INST]" + except Exception as e: + pytest.fail(f"An exception occurred: {str(e)}") # def logger_fn(user_model_dict): # return # print(f"user_model_dict: {user_model_dict}") diff --git a/litellm/tests/test_streaming.py b/litellm/tests/test_streaming.py index 78a871466e6..638253cda1b 100644 --- a/litellm/tests/test_streaming.py +++ b/litellm/tests/test_streaming.py @@ -314,58 +314,62 @@ def test_completion_cohere_stream_bad_key(): # test_completion_nlp_cloud_bad_key() -# def test_completion_hf_stream(): -# try: -# litellm.set_verbose = True -# # messages = [ -# # { -# # "content": "Hello! How are you today?", -# # "role": "user" -# # }, -# # ] -# # response = completion( -# # model="huggingface/mistralai/Mistral-7B-Instruct-v0.1", messages=messages, api_base="https://n9ox93a8sv5ihsow.us-east-1.aws.endpoints.huggingface.cloud", stream=True, max_tokens=1000 -# # ) -# # complete_response = "" -# # # Add any assertions here to check the response -# # for idx, chunk in enumerate(response): -# # chunk, finished = streaming_format_tests(idx, chunk) -# # if finished: -# # break -# # complete_response += chunk -# # if complete_response.strip() == "": -# # raise Exception("Empty response received") -# # completion_response_1 = complete_response -# messages = [ -# { -# "content": "Hello! How are you today?", -# "role": "user" -# }, -# { -# "content": "I'm doing well, thank you for asking! I'm excited to be here and help you with any questions or concerns you may have. What can I assist you with today?", -# "role": "assistant" -# }, -# ] -# response = completion( -# model="huggingface/mistralai/Mistral-7B-Instruct-v0.1", messages=messages, api_base="https://n9ox93a8sv5ihsow.us-east-1.aws.endpoints.huggingface.cloud", stream=True, max_tokens=1000 -# ) -# complete_response = "" -# # Add any assertions here to check the response -# for idx, chunk in enumerate(response): -# chunk, finished = streaming_format_tests(idx, chunk) -# if finished: -# break -# complete_response += chunk -# if complete_response.strip() == "": -# raise Exception("Empty response received") -# # print(f"completion_response_1: {completion_response_1}") -# print(f"completion_response: {complete_response}") -# except InvalidRequestError as e: -# pass -# except Exception as e: -# pytest.fail(f"Error occurred: {e}") +def test_completion_hf_stream(): + try: + litellm.set_verbose = True + # messages = [ + # { + # "content": "Hello! How are you today?", + # "role": "user" + # }, + # ] + # response = completion( + # model="huggingface/mistralai/Mistral-7B-Instruct-v0.1", messages=messages, api_base="https://n9ox93a8sv5ihsow.us-east-1.aws.endpoints.huggingface.cloud", stream=True, max_tokens=1000 + # ) + # complete_response = "" + # # Add any assertions here to check the response + # for idx, chunk in enumerate(response): + # chunk, finished = streaming_format_tests(idx, chunk) + # if finished: + # break + # complete_response += chunk + # if complete_response.strip() == "": + # raise Exception("Empty response received") + # completion_response_1 = complete_response + messages = [ + { + "content": "Hello! How are you today?", + "role": "user" + }, + { + "content": "I'm doing well, thank you for asking! I'm excited to be here and help you with any questions or concerns you may have. What can I assist you with today?", + "role": "assistant" + }, + { + "content": "What is the price of crude oil?", + "role": "user" + }, + ] + response = completion( + model="huggingface/mistralai/Mistral-7B-Instruct-v0.1", messages=messages, api_base="https://n9ox93a8sv5ihsow.us-east-1.aws.endpoints.huggingface.cloud", stream=True, max_tokens=1000 + ) + complete_response = "" + # Add any assertions here to check the response + for idx, chunk in enumerate(response): + chunk, finished = streaming_format_tests(idx, chunk) + if finished: + break + complete_response += chunk + if complete_response.strip() == "": + raise Exception("Empty response received") + # print(f"completion_response_1: {completion_response_1}") + print(f"completion_response: {complete_response}") + except InvalidRequestError as e: + pass + except Exception as e: + pytest.fail(f"Error occurred: {e}") -# test_completion_hf_stream() +test_completion_hf_stream() # def test_completion_hf_stream_bad_key(): # try: diff --git a/pyproject.toml b/pyproject.toml index 13a808dd08d..545301001ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "litellm" -version = "0.1.802" +version = "0.1.803" description = "Library to easily interface with LLM API providers" authors = ["BerriAI"] license = "MIT License"