zou-group / textgrad

TextGrad: Automatic ''Differentiation'' via Text -- using large language models to backpropagate textual gradients.
http://textgrad.com/
MIT License
1.6k stars 130 forks source link

Quick start #2

Closed andresckamilo closed 3 months ago

andresckamilo commented 3 months ago

I tried the code from the quick start guide in the repository, but it is not working correctly and gives me errors. The commands and the imports don't seem to match properly.

For the first code example, I encountered this error:

AttributeError: 'str' object has no attribute 'value'

When trying it with a question, I got the following error:

TypeError: 'str' object is not callable
andresckamilo commented 3 months ago

I found the solution. The problem is that in the quick start guide, the engine is defined as a string (str), but it shouldn't be. In the source code, the engine is an instance of engineLM, so using a string causes the error.

Here is the corrected code:

engine = tg.get_engine(engine_name='gpt-4o')
model = tg.BlackboxLLM(engine)

With this change, everything else works correctly.

mertyg commented 3 months ago

Great catch -- I'm sorry for the delay in responding. We'll push the latest version to pypi soon. Also in the meantime, you can clone the repo, run pip install -e . and work with the latest and greatest.

One other error you may run into: We should have been pushing question to the model object, instead of question_string.

apologies again for all this

andresckamilo commented 3 months ago

Oh yes, I also got that, but I was able to get it done changing it by that, since the sintax is similar to Pytorch. No worries, thanks for the library! It is really nice.

mertyg commented 3 months ago

That’s great to hear — appreciate your interest @andresckamilo !