Skip to content

Instantly share code, notes, and snippets.

View bLopata's full-sized avatar
:shipit:
egregorious

Ben Lopata bLopata

:shipit:
egregorious
  • USA
View GitHub Profile

Let's break down how the new logic handles errors that occur in the middle of the stream:

  1. Error Detection: The convo_turn generator function now has its own try-except block. This allows it to catch any exceptions that occur during the streaming process, including those that might happen midstream.

  2. Error Handling: If an error occurs during streaming (either in the thought generation or response generation), the following will happen:

    • The error is logged using logging.error(f"Error during streaming: {str(e)}").
    • An error message is yielded to the client: yield f"Error: {str(e)}".
  • The generator function returns, effectively ending the stream.
bind message has 2616 parameter formats but 0 parameters
at Parser.parseErrorMessage (/Users/ben/Documents/Github/GenoPalate/GenoPalateWeb/packages/common/node_modules/pg-protocol/src/parser.ts:369:69)
at Parser.handlePacket (/Users/ben/Documents/Github/GenoPalate/GenoPalateWeb/packages/common/node_modules/pg-protocol/src/parser.ts:188:21)
at Parser.parse (/Users/ben/Documents/Github/GenoPalate/GenoPalateWeb/packages/common/node_modules/pg-protocol/src/parser.ts:103:30)
at Socket.<anonymous> (/Users/ben/Documents/Github/GenoPalate/GenoPalateWeb/packages/common/node_modules/pg-protocol/src/index.ts:7:48)
at Socket.emit (node:events:527:28)
at Socket.emit (node:domain:475:12)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Socket.Readable.push (node:internal/streams/readable:234:10)
defmodule RobotSimulator.Guards do
@moduledoc """
Custom guards to validate position and direction in RobotSimulator.
"""
@directions [:north, :east, :south, :west]
defguard is_position(pos) when is_integer(elem(pos, 0) + elem(pos, 1)) and tuple_size(pos) == 2
defguard is_direction(dir) when is_atom(dir) and dir in @directions
end
@bLopata
bLopata / robot_simulator.ex
Last active December 26, 2019 20:05
Robot simulator program to verify actions. Custom guards in create/2 to validate position {x, y} coordinates and direction.
defmodule RobotSimulator do
defstruct position: {0, 0}, direction: :north
@type t :: %__MODULE__{
position: {integer(), integer()},
direction: :north | :east | :south | :west
}
@directions [:north, :east, :south, :west]