ahyatt / llm

A package abstracting llm capabilities for emacs.
GNU General Public License v3.0
142 stars 19 forks source link

Fix issue with JSON array parser nor emitting all objects #31

Closed r0man closed 3 months ago

r0man commented 3 months ago

Hi @ahyatt,

I made some progress. I can use the Vertex provider with Ellama and the tester runs most of the tests fine. There is some issue with function calling.

==============================
Testing for llm-vertex
==============================

Testing provider llm-vertex for chat
SUCCESS: Provider llm-vertex provided a response Very good, sir.  One of the many cool features of emacs is the ability to use regular expressions to search and replace text.  This can be very useful for finding and replacing specific patterns of text, such as email addresses or phone numbers.  For example, to replace all instances of the email address "username@example.com" with "newusername@example.com", you would use the following regular expression:

s/username@example.com/newusername
Testing provider llm-vertex for chat
Testing provider llm-vertex for streaming chat
SUCCESS: Provider llm-vertex provided a response Very good, sir.  One random cool feature of emacs is the ability to play Tetris within the editor.  I would advise against doing so during your work hours, however.
Testing provider llm-vertex for conversation
SUCCESS: Provider llm-vertex provided a conversation with responses (1. I understand. For each response, I will include its ordinal number in the first sentence, along with a statement to confirm that I have access to the full conversation history. For example, this is my first response. I acknowledge that I have access to the full conversation history up to this point. 2. I acknowledge that I have access to the full conversation history up to this point, including the previous message, which is the second message. 3. I acknowledge that I have access to the full conversation history up to this point, including the previous two messages, which are the second and third messages.)
Testing provider llm-vertex for conversation
SUCCESS: Provider llm-vertex provided a streamed response in 1 parts:
In the quaint town of Willow Creek, nestled amidst rolling hills and whispering willows, there lived an unassuming boy named Ethan. Life had always been ordinary for him, until the day he stumbled upon a peculiar backpack in the dusty attic of his grandmother's house.

As Ethan reached out to touch the worn leather straps, he felt a surge of warmth coursing through his body. The backpack seemed to hum with an ethereal energy, beckoning him to unravel its secrets. With trembling hands, he unzipped the main compartment and gasped in amazement.

Inside, he discovered an array of shimmering objects: a kaleidoscope of colored crystals, a quill pen that seemed to dance on its own, and a small, golden key. As he explored further, he noticed a faint inscription etched into the lining of the backpack: "The Key to Wonders."

Intrigued and filled with a sense of adventure, Ethan slipped the backpack over his shoulders and stepped out into the unknown. As he walked, the crystals emitted a soft glow, illuminating his path like a thousand tiny stars. The quill pen began to scribble in the air, forming intricate patterns that seemed to whisper ancient secrets.

Ethan soon realized that the backpack was no ordinary object. It possessed the power to unlock hidden realms and grant him extraordinary abilities. With the crystals, he could manipulate light and create illusions. The quill pen allowed him to write stories that came to life before his very eyes. And the golden key opened doors to secret passages and forgotten treasures.

As Ethan journeyed through Willow Creek, he encountered challenges and obstacles at every turn. He used his newfound powers to overcome them, helping those in need and righting wrongs. He befriended a talking cat named Midnight, who possessed a mischievous sense of humor and a deep knowledge of the town's hidden history.

Together, Ethan and Midnight embarked on a series of thrilling adventures. They explored ancient ruins, solved cryptic puzzles, and faced off against shadowy villains who sought to control the backpack's magic. Ethan's courage and compassion grew with each passing day, as he learned to wield his powers responsibly.

One fateful night, as Ethan and Midnight stood atop the highest hill overlooking Willow Creek, they witnessed a sinister plot unfolding. A group of evil sorcerers were attempting to steal the backpack and use its magic for their own wicked purposes.

Without hesitation, Ethan and Midnight charged into battle. Ethan summoned his crystals, creating a blinding light that disoriented the sorcerers. Midnight used his sharp claws and quick reflexes to defend them. The quill pen danced across the air, writing spells that bound the sorcerers and thwarted their plans.

In the end, Ethan and Midnight emerged victorious, saving Willow Creek from the clutches of evil. The town erupted in cheers and celebration, as they hailed Ethan as their hero. From that day forward, Ethan became known as the "Keeper of Wonders," a guardian of the magic backpack and a symbol of hope for the people of Willow Creek.

And so, the legend of the magic backpack was passed down through generations, inspiring countless children to dream of a world where anything was possible and the power of imagination could shape their destiny.
Testing provider llm-vertex for conversation
SUCCESS: Provider llm-vertex called a function and got result ((describe_function . buffer-file-name))
SUCCESS: Provider llm-vertex provided a conversation with responses (1 2 3)
SUCCESS: Provider llm-vertex provided a conversation with responses 1. I understand. I will respond to each message with the ordinal number of my response, and let you know if I appear to be missing anything in the conversation history.
2. Yes, I understand. This is the second message in the conversation.
3. Yes, I understand. This is the third message in the conversation. Is there anything else I can help you with today?
SUCCESS: Provider llm-vertex called a function and got a result of ((describe_function . buffer-file-name))
SUCCESS: Provider llm-vertex called a function and got a final result of 

At this point the stacktrace is shown:

Debugger entered--Lisp error: (wrong-type-argument characterp (function (name . "describe_function") (arguments (function_name . "buffer-file-name"))))
  concat("" ((function (name . "describe_function") (arguments (function_name . "buffer-file-name")))))
  (setq streamed-text (concat streamed-text response))
  (progn (setq streamed-text (concat streamed-text response)) (llm-request-callback-in-buffer buf partial-callback streamed-text))
  (if (> (length response) 0) (progn (setq streamed-text (concat streamed-text response)) (llm-request-callback-in-buffer buf partial-callback streamed-text)))
  (if response (if (> (length response) 0) (progn (setq streamed-text (concat streamed-text response)) (llm-request-callback-in-buffer buf partial-callback streamed-text))) nil)
  (let* ((response (and t (llm-vertex--get-chat-response element)))) (if response (if (> (length response) 0) (progn (setq streamed-text (concat streamed-text response)) (llm-request-callback-in-buffer buf partial-callback streamed-text))) nil))

You know more about this. Would you be able to take over here?

Thanks Roman.

ahyatt commented 3 months ago

Thanks! Yes, let me look at the function calling.

ahyatt commented 3 months ago

I now have a completely working Gemini & Vertex! Woo!

I think there's only two things left, both probably on the plz side and not with your code: first, I need some way to clean up the curl buffers. Maybe there's some standard way to do this, but I don't know what it is. For example, on sync requests, there is no :finally or :then available to hook onto to delete the process buffer.

The second issue is with debugging. It would be pretty useful to have a way to see the curl command, and the traffic going back and forth.

r0man commented 3 months ago

Hi @ahyatt,

that's great! About the buffers, that's probably my fault. I think I didn't add any code when I changed the :as option from 'response to 'buffer. I see what I can do about it.

The curl command is probably something we need to do in plz itself. About the traffic I'm not sure. The streaming media types delete the content from the buffer once a part has been successfully parsed. Additionally I believe debugging code in the process filter with Edebug is also a bit complicated. I believe this is due to the process exiting while you are still in the debugger. And the exit of the process triggering other code that runs while you are still in Edebug. At least this was my impression dealing with this. I might be wrong though.

One thing I did was whenever the process filter gets called to append the whole content into a "snapshots" buffer. That way I could see what the buffer looked like. We could put this under a debug flag or something. Wdyt?